| | Expression | Description |
|---|
| 1 | //child | Return a NodeSet containing ALL XML tags in the document with the name 'child'. |
| 2 | //child[@name='beta'] | Return a NodeSet containing ALL XML tags in the document with the name 'child'
that have an attribute called 'name' with a value of 'beta'. |
| 3 | /parent/child[@name='beta']/@id | Look for all direct 'child' children of the 'parent' tag for which
the 'name' attribute has the value 'beta'. Having found this set - return
the values of all of the price attributes of each selected element. |
| 4 | /parent/child[@name='alpha' or @id=2] | Look for all direct 'child' children of the 'parent' tag that have
either a 'name' with value 'alpha' or an 'id' attribute
with value '2'. Return the results as a set of nodes. |
| 5 | count(/parent/child) | Count the number of 'child' tags that are direct chidren of a 'parent' tag. |
| 6 | /parent/child|parent/pet | Return the union of the set of 'children' and 'pet' tags. |
| 7 | //*[starts-with(name(),'p')] | Return all nodes - anywhere in the document - that have a name
with 'p' as the first letter. |
| 8 | //pet[contains(string(),'dog')] | Return the set of tags for which the string value contains the word
'dog'. Note that XPath 'string' value is not the same as the XML
parsers string value. XPath generates the string value of a tag as the
concatenation of all the text descendants of the target tag. In
this case the search looks at the content and NOT at the contents of
formatting and other markup. |
| 9 | /parent/(child | pet)/description | Take all children of 'content' called EITHER body OR head. From that
set - select all tags called 'rb:script'. |
| 10 | //*[@id>1 and @id<4] | Return the set of all tags that have an 'id' attribute and in which the
(numeric) value of that id is greater than 2 and less than 4. Note
that XPath numbers are double precision floating point numbers! |
| 11 | /parent/child[1]/(@id>1 and @id<4) | Return 'true' if the value of the 'id' attribute of the first child of the parent is between 1 and 4. If
the attribute doesn't exist at all then the value evaluates to false. |
| 12 | /parent/*[3 to 5] | Return the third through 5th tags contained in the parent tag.
|