Chapter 3 Building an XML model


XPath abbreviated syntax

You can use the following abbreviated syntax to define an XPath expression:

Syntax Description
/ Root node of the XML document. It is the root element with its ramifications
. Selects the context node. It is the current element (on which an identity constraint is defined) with its ramifications
.. Selects the context node parent
* Selects all the child elements of the context node
employee Selects all the employee child elements of the context node
s:employee Selects all the employee child elements of the context node, defined in the namespace with the "s" prefix
@numEmployee Selects the numEmployee attribute of the context node
@* Selects all the attributes of the context node
../@numEmployee Selects the numEmployee attribute of the context node parent
employee[1] Selects the first employee child element of the context node
employee[last()] Selects the last employee child element of the context node
*/employee Selects all the employee grandchildren of the context node
//employee Selects all the employee descendants of the root node
.//employee Selects the employee descendants of the context node
company//employee Selects the employee descendants of the company child elements of the context node
//company/employee Selects all the employee elements with company as parent element in the context node
/book/chapter[2]/section[3] Selects the third section in the second chapter of the book
employee[@dept="doc"] Selects all the employee child elements of the context node with a dept attribute set to doc
employee[@dept="doc"][3] Selects the third employee child element of the context node with a dept attribute set to doc
employee[3][@dept="doc"] Selects the third employee child element of the context node only if it has a dept attribute set to doc
chapter[title] Selects the chapter child elements of the context node with at least one title child element
chapter[title="About this book"] Selects the chapter child elements of the context node with at least one title child element with a text content set to About this book
employee[@numEmployee and @dept] Selects all the employee child elements of the context node with the numEmployee and dept attributes
text() Selects all the child nodes of the text context node

 


Copyright (C) 2005. Sybase Inc. All rights reserved.