Accessing XML Data Using XPath Expressions
With the parsing out of the way, we can turn to how to
access parts of the XML data. The JSTL XML library contains a number
of actions for this purpose, similar to the ones
you’re familiar with from the JSTL core library:
<x:forEach>. The main difference between the
XML and the core flavor is that the XML actions use a special
language for working with XML data, named XPath, instead of the
standard JSP EL. XPath 1.0 is a W3C recommendation that has been
around since 1999, and it’s used in XSLT stylesheets
and other XML applications. The language details are beyond the scope for this book,
but here’s a brief summary.
An XPath expression identifies one or more nodes (root, elements,
attributes, namespace attributes, comments, text, and processing
instructions) in an XML document. The simplest expression type is a
similar to a Unix filesystem path, to a set of nodes in the document.
For instance, the path /meerkat/image/url
<url> element in the Meerkat
... <meerkat> <title>Meerkat: An Open Wire Service</title> <link>http://meerkat.oreillynet.com</link> <description> Meerkat is a Web-based syndicated content reader providing a simple interface to RSS stories. While maintaining the original association of a story with a channel, Meerkat's focus is on chronological order -- the latest stories float to the top, regardless of their ...