XPath

 

Home
SF Project
SF Download
Javadoc
Example
Porting
Thermopylae
XPath
SF Feedback
The Sparta XPath expression languages is a subset of the full Xpath grammar.[1]. It supports only the abbreviated syntax.[2]

 

Examples

(These examples are taken from http://www.w3.org/TR/xpath#path-abbrev)

 

para:
selects the para element children of the context node
*:
selects all element children of the context node
text():
selects all text node children of the context node
@name:
selects the name attribute of the context node
para[1]:
selects the first para child of the context node
*/para:
selects all para grandchildren of the context node
/doc/chapter[5]/section[2]:
selects the second section of the fifth chapter of the doc
chapter//para:
selects the para element descendants of the chapter element children of the context node
//para:
selects all the para descendants of the document root and thus selects all para elements in the same document as the context node
//olist/item:
selects all the item elements in the same document as the context node that have an olist parent
.:
selects the context node
.//para:
selects the para element descendants of the context node
..:
selects the parent of the context node
../@lang:
selects the lang attribute of the parent of the context node
para[@type="warning"]:
selects all para children of the context node that have a type attribute with value warning

The following examples are currently not supported

@*:
selects all the attributes of the context node
para[last()]:
selects the last para child of the context node
chapter[title="Introduction"]:
selects the chapter children of the context node that have one or more title children with string-value equal to Introduction
chapter[title]:
selects the chapter children of the context node that have one or more title children
para[@type="warning"][5]:
selects the fifth para child of the context node that has a type attribute with value warning
para[5][@type="warning"]:
selects the fifth para child of the context node if that child has a type attribute with value warning
employee[@secretary and @assistant]:
selects all the employee children of the context node that have both a secretary attribute and an assistant attribute

Grammar

 

location_path :=
slash? step ( slash step )*
slash ::=
'/'
| '//'
step :=
node_test ( '[' expr ']' )?
node_test :=
'.'
'..'
| '*'
| 'text()'
| name
expr :=
'@' name
| '@' name = '"' string '"'
| '@' name != '"' string '"'
| number
 

SourceForge Logo