[html]

Basics of XPath

R. Alexander Milowski

milowski at sims.berkeley.edu

#1

XPath

#2

Like Directory Paths

#3

Node Set Results

#4

Selecting Attributes

#5

Names and Namespaces

#6

No Prefix = No Namespace

#7

Wildcards

#8

Context Node

#9

Parent and Ancestors

#10

Conditional Matching

#11

Skipping Levels

#12

Special Functions

#13

The Real Story

#14

Trees and XML

For the computer scientists:

#15

Relationships in a Tree

Figure 1. Relationships from the red node.

#16

Additional XML Relationships

#17

Axes are Directions on Relationships

  • Axes are just a traversal of a relationship.

  • Some are tree relationships:

    • ancestor, ancestor-or-self

    • parent, child, self

    • descendant, descendant-or-self

    • following, following-sibling

    • preceding, preceding-sibling

  • And some extras:

    • attribute

    • namespace

#18

Axis Syntax

#19

Axis Specifics

#20

Principal Node Type

#21

Axis Direction

#22

Axis Direction - Example

For example, give the following

<doc>
<a/><b/><c/>
<target/>
<d/><e/><f/>
</doc>

These expressions evaluate:

target/preceding-sibling::* → elements 'c' b' 'a'.

target/following-sibling::* → elements 'd' 'e' 'f'.

#23

Abbreviated Syntax Equivalences

Abbreviation Equivalence
../name
parent::name
name
child::name
//name
descendant::name
.
self::node()
*
child::*
@*
attribute::*
@name
attribute::name

#24

What use is this?