Looking to Reprint this content?
By Steve Muench
Price: $44.95 USD
£31.95 GBP
Cover | Table of Contents | Colophon
<?xml version="1.0"?>
<transaction>
<account>89-344</account>
<buy shares="100">
<ticker exch="NASDAQ">WEBM</ticker>
</buy>
<sell shares="30">
<ticker exch="NYSE">GE</ticker>
</sell>
</transaction>
<transaction> tag. Nested inside this opening tag and its
matching </transaction> closing tag, other
tags and text encode
nested structure and data values respectively. Any tag can carry a
list of one or more named
attribute="value"
entries as well, like
shares="
nn
"
on <buy> and <sell> and
exch="
xxx
"
on <ticker>.<table>, <img>, and <a> for tables, images, and
anchors. In contrast, with XML you can invent any set of meaningful
tags to suit your current data encoding needs, or reuse an existing
set that someone else has already defined. Using XML and an
appropriate set of tags, you can encode data of any kind, from highly
structured database query results like the following:
<Task>, or can contain as many elements and
attributes as you need. An example document that uses the
<Task> vocabulary looks like this:<Task Name="JDeveloper 3.1">
<Task Name="Improved XML Support">
<Task Name="Syntax-Check XML/XSL" Dev="Steve"/>
<Task Name="Color-Coded Editing" Dev="Yoshi"/>
<Task Name="Run XSQL Pages" Dev="Bret"/>
</Task>
<Task Name="Improved Debugging Support">
<Task Name="Remote Debugging">
<Task Name="JServer Debugging" Dev="Jimmy"/>
<Task Name="Apache JServ Debugging" Dev="Liz"/>
</Task>
</Task>
</Task>
<Task>, or can contain as many elements and
attributes as you need. An example document that uses the
<Task> vocabulary looks like this:<Task Name="JDeveloper 3.1">
<Task Name="Improved XML Support">
<Task Name="Syntax-Check XML/XSL" Dev="Steve"/>
<Task Name="Color-Coded Editing" Dev="Yoshi"/>
<Task Name="Run XSQL Pages" Dev="Bret"/>
</Task>
<Task Name="Improved Debugging Support">
<Task Name="Remote Debugging">
<Task Name="JServer Debugging" Dev="Jimmy"/>
<Task Name="Apache JServ Debugging" Dev="Liz"/>
</Task>
</Task>
</Task>
Oracle
JDeveloper and the
current version number of the product might appear in many of the
questions and answers. We can define two entities to represent this
repetitive text using the syntax:<!ENTITY jdev "Oracle JDeveloper"> <!ENTITY ver "3.1">
<Question>What is the current version of &jdev;?</Question> <Answer>The current version is &jdev; &ver;</Answer>
<,
>, ', and
"). References to user-defined entities
like &jdev; start with an ampersand character
and end with a semicolon, with the entity name in between. Like the
default attribute values we saw earlier, these entities can be
defined in an external DTD file, or right in the current document by
including them in the local DTD section known as the
internal subset
. The syntax for including these entity
definitions in the document you're working on (when you do not
control the DTD or when the entities are not interesting enough to be
placed there for global use) looks like this:<?xml version="1.0"?>
<!DOCTYPE FAQ-List SYSTEM "FAQ-List.dtd"[
<!-- Internal subset adds local definitions -->
<!ENTITY jdev "Oracle JDeveloper">
<!ENTITY ver "3.1">
]>
<FAQ-List>
<FAQ Submitter="smuench@oracle.com">
<Question>Is it easy to get started with XML?</Question>
<Answer>Yes!</Answer>
</FAQ>
<FAQ Submitter="smuench@oracle.com" Level="Beginner">
<Question>What is the current version of &jdev;?</Question>
<Answer>The current version is &jdev; &ver;</Answer>
</FAQ>
</FAQ-List>dir or
ls allow you to search for matching files that
have been organized into those nested directories. Consider the
directory hierarchy of drive M: as shown in Figure 2.9 using the Windows Explorer.
ls /MovieList/Movie/Cast/Actor/*
/MovieList/Movie/Cast/Actor/First /MovieList/Movie/Cast/Actor/Last /MovieList/Movie/Cast/Actor/Award
|
XPath Expression Syntax |
|---|
<?xml version="1.0"?>
<!DOCTYPE FAQ-List SYSTEM "FAQ-List.dtd">
<FAQ-List>
<FAQ Submitter="smuench@oracle.com">
<Question>Is it easy to get started with XML?</Question>
<Answer>Yes!</Answer>
</FAQ>
<FAQ Submitter="derek@spinaltap.com" Level="Advanced">
<Question>Are we going to play Stonehenge?</Question>
<Answer>But of course</Answer>
</FAQ>
</FAQ-List>
<?xml version="1.0"?>
<!DOCTYPE FAQ-List SYSTEM "FAQ-List.dtd">
<FAQ-List>
<FAQ Submitter="smuench@oracle.com">
<Question>Is it easy to get started with XML?</Question>
<Answer>Yes!</Answer>
</FAQ>
<FAQ Submitter="derek@spinaltap.com" Level="Advanced">
<Question>Are we going to play Stonehenge?</Question>
<Answer>But of course</Answer>
</FAQ>
</FAQ-List>
create table faq_table( category VARCHAR2(30), question VARCHAR2(4000), answer VARCHAR2(4000), qlevel NUMBER, submitted_by VARCHAR2(80) );
<xsql:include-xsql>
.
We also notice that by including one extra line at the top of our
page, like this:<?xml-stylesheet type="text/xsl" href="FAQ-In-XML.xsl"?>
<?xml version="1.0"?> <!-- FAQXML.xsql: Show FAQ.xsql in Standard FAQ-List.dtd Vocabulary --> <?xml-stylesheet type="text/xsl" href="FAQ-In-XML.xsl"?> <xsql:include-xsql href="FAQ.xsql" xmlns:xsql="urn:oracle-xsql"/>
<xsql:include-xsql> to include the XML results from
our previous work, and associates the
FAQ-In-XML.xsl stylesheet we created above to
this page. Now, when we try from our browser to request the new XSQL
page for the jdev category of frequently asked
questions, as shown in Figure 3.2, we see our
dynamic information in our <FAQ-List> format with no manual
steps involved. Pretty neat.
<?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>
<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>
<xsl:for-each> are looping over Sun's XML format and
constructing the <ROWSET>, <ROW>, and column-name
elements required for the automatic insert. As in all of our other
stylesheets, we use <xsl:value-of> to plug in the
Q and A children element values
from the current /Servlets-FAQ/FAQ element as the
values of our <QUESTION> and <ANSWER> elements. Note that
because Sun doesn't keep track of the difficulty level in the
FAQ format, we're using a constant value of
1 in our stylesheet to default to a value that
makes sense to our system. Also, we use a constant value of
SERVLETS for the category to make sure that the
information from FAQs for Servlets is placed in an appropriate
category for searching through our faq_table.myi—and a Search for
pop-up appears. JDeveloper incrementally jumps you to the first file
matching the letters you've typed in so far, as illustrated in
the figure, so typically only a few letters are required to jump to
the file you want.
SQL> CREATE USER xmlbook IDENTIFIED BY xmlbook; User created. SQL> GRANT connect, resource, query rewrite TO xmlbook; Grant succeeded.
SQL> CONNECT xmlbook/xmlbook Connected SQL> SELECT sysdate FROM dual; SYSDATE --------- 23-APR-00
<!-- claim77804.xml -->
<Claim>
<ClaimId>77804</ClaimId>
<Policy>12345</Policy>
<Settlements>
<Payment Approver="JCOX">1000</Payment>
<Payment Approver="PSMITH">1850</Payment>
</Settlements>
<DamageReport>
The insured's <Vehicle Make="Volks">Beetle</Vehicle>
broke through the guard rail and plummeted into a ravine.
The cause was determined to be <Cause>faulty brakes</Cause>.
Amazingly there were no casualties.
</DamageReport>
</Claim>
CREATE DIRECTORY directoryname AS 'OS-Specific-Dirname';
CREATE DIRECTORY xmlfiles AS 'C:\xmlfiles';
|
PL/SQL Package Name
|
Description
|
|---|---|
xmlparser
|
Contains datatypes, functions, and procedures for parsing XML
|
xmldom
|
Contains datatypes, functions, and procedures for creating and
manipulating the members of an XML document's object model like
elements, attributes, text, comments, etc.
|
xslprocessor
|
Contains datatypes, functions, and procedures for transforming XML
documents using XSLT stylesheets and searching an in-memory XML
document using XPath expressions |
xmldom package provides a completely programmatic
way of hunting through the entire tree of nodes of an XML document to
find what you're looking for. We'll see in this section
how XPath's searching of in-memory XML makes it all declarative
and so much easier.<!-- claim77804.xml -->
<Claim>
<ClaimId>77804</ClaimId>
<Policy>12345</Policy>
<Settlements>
<Payment Approver="JCOX">1000</Payment>
<Payment Approver="PSMITH">1850</Payment>
</Settlements>
<DamageReport>
The insured's <Vehicle Make="Volks">Beetle</Vehicle>
broke through the guard rail and plummeted into a ravine.
The cause was determined to be <Cause>faulty brakes</Cause>.
Amazingly there were no casualties.
</DamageReport>
</Claim>
/Claim/Policy
Content-Type of
text/xml.http://www.w3.org/TR/1999/REC-xslt-19991116), and that allows you to transform XML in one format
into XML, HTML, or plain text of another format.sqlplus xmlbook/xmlbook
oracle.xml.sql.query.OracleXMLQuery class by
running the following SQL statement:SELECT SUBSTR(dbms_java.longname(object_name),1,35) AS class, status
FROM all_objects
WHERE object_type = 'JAVA CLASS'
AND object_name = dbms_java.shortname('oracle/xml/sql/query/OracleXMLQuery')
CLASS STATUS ----------------------------------- ------- oracle/xml/sql/query/OracleXMLQuery VALID