Selecting XML Document Nodes with XPath

XPath is a non-XML declarative query language (defined by the W3C) for selecting an XML document’s infoset items as one or more nodes. For example, you can use XPath to locate Listing 15-1’s third ingredient element and return this element node.

XPath is often used to simplify access to a DOM tree’s nodes, and it is also used in the context of XSLT (discussed in the next section) where it’s typically employed to select those input document elements (via XPath expressions) that are to be copied to an output document. Java and Android support XPath 1.0, which is assigned package javax.xml.xpath.

In this section, I first acquaint you with the XPath language. I then demonstrate how XPath simplifies the selection ...

Get Learn Java for Android Development, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.