Processing XML Data

XSLT is great for transforming an XML source into another format, but sometimes you need to process the XML data in other ways. For instance, you may want to use part of the XML data in a database query to get additional information and compose a response that merges the two data sources, or reformat date and numeric information in the XML source according to the user’s preferred locale. To process XML data in this way, the JSTL XML library includes a number of actions for picking out pieces of an XML document, as well as iteration and conditional actions similar to the ones in the core library, but adapted to work specifically with XML data.

In this section we look at an example that uses most of the JSTL XML actions. The XML data comes from the O’Reilly Meerkat news feed. Meerkat scans a large set of Rich Site Summary (RSS) -- an XML application suitable for news, product announcements, and similar content -- sources frequently and makes the aggregated data available in a number of formats, including a superset of the RSS format that includes category, source, and date information for each story. You can learn more about Meerkat and how to use it at http://www.oreillynet.com/pub/a/rss/2000/05/09/meerkat_api.html. Example 14-5 shows a sample of the XML data that Meerkat can deliver.

Example 14-5. Meerkat XML news feed format

<?xml version="1.0"?> <!DOCTYPE meerkat_xml_flavour SYSTEM "http://meerkat.oreillynet.com/dtd/meerkat_xml_flavour.dtd"> <meerkat> <title>Meerkat: ...

Get JavaServer Pages, Second 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.