XML Path Language (XPath)

XML Foundations (INFOSYS 242)

Erik Wilde, UC Berkeley iSchool
Tuesday, September 19, 2006
Creative Commons License

This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.5 License.

Abstract

XML structures data into a rather small number of different constructs, most notably elements and attributes. The XML Path Language (XPath) defines a way how to select parts of XML documents, so that they can be used for further processing. XPath's primary use in in XSL Transformations (XSLT), but other XML technologies use it as well, e.g. XML Schema. XPath is a very compact language with a syntax that resembles the path expressions which are well-known from file systems. These path expressions, however, are generalized and therefore much more powerful than the rather simple path expressions in file systems. Because of its use in different XML technologies, XPath is one of the most important XML core technologies.

Outline (Why XPath?)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Selecting Parts of XML Documents

Making Selection Reusable

How XPath Evolved

Outline (How XPath Works)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Outline (The XPath Tree Model)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Starting from the Infoset

What is Not in the XPath Tree

Outline (XPath Evaluation)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Tree In / Selection Out

Outline (XPath Location Paths)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Location Path Structure

Outline (XPath Node Tests)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

File System vs. XPath Paths

File System Path: / usr / local / apache / bin /
# Selected Nodes: 1 → 1 1 1 1
XPath: / html / body / table / thead / tr
# Selected Nodes: 1 → 1 1 6 4 12

Tests for Nodes

Outline (XPath Axes)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Where Do You Want to Go Today?

Ancestor Axis

Ancestor-or-self Axis

Attribute Axis

Child Axis

Descendant Axis

Descendant-or-self Axis

Following Axis

Following-sibling Axis

Namespace Axis

Parent Axis

Preceding Axis

Preceding-Sibling Axis

Self Axis

Putting it all Together

Outline (Predicates)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Location Step Filters

Location Path Processing

Outline (XPath Expressions)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Beyond Location Paths

XPath Usages

Outline (XPath Functions)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

Function Library

Using Functions

Outline (Limitations of XPath)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

XPath Selects

Outline (Conclusions)

  1. Why XPath? [3]
  2. How XPath Works [3]
    1. The XPath Tree Model [2]
    2. XPath Evaluation [1]
  3. XPath Location Paths [20]
    1. XPath Node Tests [2]
    2. XPath Axes [15]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

XPath is Important