Integrating Custom XML Sources

In this section, we’ll depart from simple examples designed to help understand the technology and provide a real-world example of a custom XSQL action handler that does something really useful. In Chapter 6 we built a class called JTidyConverter, which leveraged the freely available JTidy JavaBean to convert HTML into a well-formed XML document. Then we wrote some examples illustrating how basic XPath expressions in an XSLT stylesheet could easily extract interesting information like stock quotes from HTML returned by a live request against the Yahoo! Quotes web site. Here we will show a parallel example that illustrates how such useful, dynamic XML information can be adapted into the XSQL Pages framework. Example 16.5 shows the code for this LiveQuotes action handler.

As with our more straightforward examples earlier in this chapter, the LiveQuotes handler uses getAttributeAllowingParam to get the list of ticker symbols from the symbols attribute on the action element, then employs the JTidyConverter class to retrieve the dynamic HTML page delivered from the Yahoo! Quotes server and return it as an in-memory XML document. Rather than writing code to perform the XSLT transformation ourselves, we take advantage of the XSQL page processor’s own XSQLStylesheetProcessor, which automatically loads, caches, and pools the YahooQuotes-to-QuoteStream.xsl stylesheet. Note that we have to call getPageRequest( ).translateURL( ) so that the relative URL YahooQuotes-to-QuoteStream.xsl ...

Get Building Oracle XML Applications 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.