Acquiring Web-based XML Content
We
check out the ServletsFAQ.xml
file on
Sun’s site, which they update periodically, and notice that it
has a format like this:
<?xml version = '1.0' encoding = 'UTF-8'?> <Servlets-FAQ> <FAQ> <Q>What's the next major release of the Servlet API?</Q> <A>Servlet API 2.2</A> </FAQ> <FAQ> <Q>How do I set the age of a cookie?</Q> <A>yourCookie.setAge(120);</A> </FAQ> <FAQ> <Q>How do I save a variable in a per-user session?</Q> <A>request.getSession(true).putValue('varname','value');</A> </FAQ> </Servlets-FAQ>
We want this Servlet FAQ content and others like it from Sun’s
site to reside in our database so we can search over it together with
all of our own content. We learn that the Oracle XML SQL Utility can insert
XML documents automatically into our faq_table if they have the
canonical <ROWSET>/<ROW>
structure, so we create another
XSLT stylesheet to transform a document in Sun’s
<Servlets-FAQ>
vocabulary into a <ROWSET>/<ROW>
document:
<ROWSET xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:for-each select="/Servlets-FAQ/FAQ"> <ROW> <CATEGORY>SERVLETS</CATEGORY> <QLEVEL>1</QLEVEL> <QUESTION><xsl:value-of select="Q"/></QUESTION> <ANSWER><xsl:value-of select="A"/></ANSWER> <SUBMITTED_BY>Sun</SUBMITTED_BY> </ROW> </xsl:for-each> </ROWSET>
This time, the tables are turned and our XPath expressions in
<xsl:for-each>
are looping over Sun’s XML format and
constructing the <ROWSET>, <ROW>
, and column-name elements required for the automatic ...
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.