Home arrow XML arrow Page 3 - XPointer Basics

Revolving Around An Axis - XML

You already know how to link XML documents together with XLink, and isolate specific nodes or node collections with XPath. Now uncover the third and final piece of the XML linking jigsaw - XPointer, an experimental technology from the W3C, which allows you to create XML links to specific points or ranges within an XML document.

  1. XPointer Basics
  2. The Need For XPointer
  3. Revolving Around An Axis
  4. Proof Of The Pudding
  5. A Fragmented View
  6. A Range Of Options
  7. Asymmetrically Yours
  8. Linking Up
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 2
December 12, 2001

print this article


Since the first component of a location step is the axis, let's deal with that first. An axis defines the relationship between the current node and the nodes to be selected - whether, for example, they are children of the current node, siblings of the current node, or the parent of the current node.

The XPath specification defines the following axes:

self - the "self" axis refers to the context node itself;

parent - the "parent" axis selects the parent of the context node;

child - the "child" axis selects the children of the context node;

attribute - the "attribute" axis refers to the attributes of the context node;

These are the most commonly-used ones; however, it's quite likely that you'll also find a use for:

ancestor - the "ancestor" axis selects the parent, grandparent, great-grandparent and all other ancestors of the context node;

descendant - the opposite of the "ancestor" axis, this axis selects the children (and children's children) of the context node;

ancestor-or-self - this variant of the "ancestor" axis selects all ancestors of the context node as well as the node itself;

descendant-or-self - this variant of the "descendant" axis selects all descendants of the context node as well as the node itself;

following-sibling and preceding-sibling - these two axes contain the nodes at the same level in the document tree as the context node. Depending on which axis you use, you will get a collection of siblings which are either after or before the context node, in document order.

following and preceding - the "following" axis selects all nodes within the document tree which follow (are placed after) the context node, while the "preceding" axis selects all nodes which come before the context node.

namespace - the "namespace" axis selects all the nodes in the same namespace as the context node;

Once the relationship to be established has been defined and an appropriate node collection obtained, a node test can be used to further filter the items in the collection. This node test is connected to the axis by a double colon (::) symbol.

Typically, you would select a node on the basis of its name without using a node test; in such a case, the node type is deduced from the axis part of the location step. If, on the other hand, you'd like to select nodes on the basis of type, XPath offers some pre-defined node tests; the text() node test selects text nodes, the comment() function selects comments, the processing-instruction() function selects PIs and the generic node() function selects any and all nodes.

Finally, in case the resulting collection needs to be further broken down, XPath allows you to add optional predicates to each location step, enclosed within square braces.

>>> More XML Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: