Cover page images (keys)

XML Lecture (Week 4)

2007-03-20

Tyng-Ruey Chuang, <trc@iis.sinica.edu.tw>

Institute of Information Science
Academia Sinica, Taipei, Taiwan

XPATH Data Model

XPath models an XML document as a tree. The tree contains 7 types of node:

The root node and element nodes have an order list of child nodes. Note that XPath operates on an XML document after CDATA sections, entity references, and document type declarations have been merged into the document.

XPATH Location Paths

An XPATH location path identifies a set of nodes in a document. A location path is built out of successive location steps. Each step is evaluated relative to a particular node in the document called the context node.

Try them on! Use this example document on this XPath evaluator!

Compound Location Paths & Predicates

XPATH expressions can be formed just like Unix path expressions using /, .., ., and //. The last one, for all descendants of the context node, is new! Examples:

Each step in a location path may (but does not have to) have a predicate that selects from the node-set current at that step in the expression. Examples:

Unabbreviated Location Paths

The following abbreviated XPath expression

//person[@born<1950]/name

is the same as the following unabbreviated XPath expression

/descendant::person[attribute::born < 1950]/child::name

There are 13 axes: