XML Path Language (XPath)

XML Foundations (INFO 242)

Erik Wilde, UC Berkeley School of Information
2007-09-20
Creative Commons License

This work is licensed under a CC
Attribution 3.0 Unported 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. XSDL. XPath is a very compact language with a syntax that resembles path expressions 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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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?

Axis Peculiarities

Axes

XPath Axes

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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    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 [9]
    1. XPath Node Tests [2]
    2. XPath Axes [4]
    3. Predicates [2]
  4. XPath Expressions [2]
  5. XPath Functions [2]
  6. Limitations of XPath [1]
  7. Conclusions [1]

XPath is Important