Java Reference
In-Depth Information
Table3-2.XPath operators
and, or
Selects according to Boolean meaning.
=, !=
Equal, not equal
<, >, <=, >= Less than, greater than, LTE, GTE
|
Either/or
Using these elements and some basic operators, you can create a variety of searches. Let's
look at some examples:
//Find the topic titled 'Hamlet' and select its price.
String xpath = "/catalog/book[title='Hamlet']/price";
//Prints: Value=5.95
//Find titles of topics with multiple authors
xpath = "/catalog/book[authors]/title";
//Prints:
Value=Java Generics and Collections
//Find all title AND price elements
xpath = "//title | //price";
//Prints:
Value=King Lear
Value=6.95
Value=Hamlet
Value=5.95
Value=1984
Value=12.95
Value=Java Generics and Collections
Value=34.99
//Get the author of the second book on the list
xpath = "//book[2]/author";
//Prints:
Value=William Shakespeare
//Get the SKU attrib value of the last book on the list
xpath = "//book[last()]/@sku";
//Prints:
Value=876_pep
//Get the entire book node for Hamlet
xpath = "//book[title='Hamlet']";
//Prints the entire Hamlet node
Search WWH ::




Custom Search