start page | rating of books | rating of authors | reviews | copyrights

Book HomeXML in a NutshellSearch this book

11.4. Child Sequences

Another very common form of XPointer is one that descends exclusively along the child axis, selecting elements by their position relative to their siblings. For example, xpointer(/child::*[position() = 1]/child::*[ position( ) = 2]/child::*[position( ) = 3]) selects the third child element of the second child element of the root element of the document. Since this is so common, XPointer allows you to abbreviate this syntax by providing only the numbers of the child elements separated by forward slashes. This is called a child sequence. For example, the previous XPointer could be rewritten as a child sequence in the much more compact form /1/2/3. A child sequence should not be enclosed in xpointer( ) as a normal XPath expression would.

For example, the Motivation and Summary section of the Namespaces in XML recommendation at http://www.w3.org/TR/1999/REC-xml-names-19990114/xml-names.xml is given as a div element. It so happens that this div element is the first child element of the second child element of the root element. Therefore, the URL http://www.w3.org/TR/1999/REC-xml-names-19990114/xml-names.xml#/1/2/1 points to this section.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.