Using XML in Oracle Database Applications
Part 2: About Oracle XML Products
November 1999
(Updated June 2001) |
 |
Contents
|
Overview
Oracle XML Developer's Kit (XDK) provides components,
utilities, and interfaces you can use to take advantage of XML technology
in database applications. You can use different parts of the XDK for different
projects, depending on application requirements, programming preferences,
and development and deployment environments. Oracle has implemented support
for XML and the XDK throughout its products and applications. |
Oracle XDK
The Oracle XML Developer's Kit
(XDK)�available for Java, JavaBeans, C, C++, and PL/SQL�includes the XML
Parsers, XSL Processors, XML Class Generator, XML Transviewer Beans, and
XML Schema Processor.
XML Parsers
Oracle provides XML parsers for Java, C, C++, and
PL/SQL. Each is a stand-alone XML component that parses an XML document
(or a stand-alone DTD) so that it can be processed by an application. The
parsers support the DOM (Document Object Model) and SAX (Simple API for
XML) interfaces, XML Namespaces, validating and non-validating modes, and
XSL transformations. They are available on all Oracle platforms.

XSL Transformation Support
Beginning with version 2, the XML Parsers include
an integrated XSL Transformation (XSLT) Processor for transforming XML
data using XSL stylesheets. Using the XSLT processor, you can transform
XML documents from XML to XML, HTML, or virtually any other text-based
format.

Namespace Support
The Java, C, and C++ parsers also support XML Namespaces.
Namespaces are a mechanism to resolve or avoid name collisions between
element types (tags) or attributes in XML documents. This mechanism provides
"universal" namespace element types and attribute names whose scope extends
beyond the containing document. Such tags are qualified by uniform resource
identifiers (URIs), such as <oracle:EMP xmlns:oracle="/xml"/>.
For example, namespaces can be used to identify an Oracle <EMP>
data element as distinct from another company's definition of an <EMP>
data element. Thus, an application can identify elements and attributes
it is designed to process. The Java, C, and C++ parsers support namespaces
by recognizing and parsing universal element types and attribute names,
as well as unqualified "local" element types and attribute names.
Validating and Non-Validating Mode Support
The Java, C, and C++ parsers can parse XML in validating
or non-validating modes. In non-validating mode, the parser verifies that
the XML is well-formed and parses the data into a tree of objects that
can be manipulated by the DOM API. In validating mode, the parser verifies
that the XML is well-formed and validates the XML data against the DTD
(if any). Validation involves checking whether the attribute names and
element tags are legal, whether nested elements belong where they are,
and so on.
About DOM and SAX APIs
XML APIs generally fall into two categories: event-based
and tree-based. An event-based API (such as SAX) uses callbacks to report
parsing events to the application. The application deals with these events
through customized event handlers. Events include the start and end of
elements and characters. Unlike tree-based APIs, event-based APIs usually
do not build in-memory tree representations of the XML documents. Therefore,
in general, SAX is useful for applications that do not need to manipulate
the XML tree, such as search operations, among others. A tree-based API
(such as DOM) builds an in-memory tree representation of the XML document.
It provides classes and methods for an application to navigate and process
the tree. In general, the DOM interface is most useful for structural manipulations
of the XML tree, such as reordering elements, adding or deleting elements
and attributes, renaming elements, and so on. The Oracle9i XDK supports
both the DOM 2.0 and SAX 2.0 specifications.
The following figure shows an XML document and
corresponding SAX and DOM representations.
| XML Document |
SAX Events |
DOM Tree |
<?xml version="1.0"?>
<EMPLIST>
<EMP>
<ENAME>MARTIN</ENAME>
</EMP>
<EMP>
<ENAME>SCOTT</ENAME>
</EMP>
</EMPLIST>
|
|
start document
start element: EMPLIST
start element: EMP
start element: ENAME
characters: MARTIN
end element: EMP
start element: EMP
start element: ENAME
characters: SCOTT
end element: EMP
end element: EMPLIST
end document
|
|
 |
Example: Java XML Parser
The following Java code uses the XML Parser for Java
v2 to parse an XML document, then uses the DOM API to manipulate the XML
data, and finally uses the XSLT Processor API to transform the data.
import org.w3c.dom.*;
import java.util.*;
import java.io.*;
import java.net.*;
import oracle.xml.parser.v2.*;
public class XSLTransform
{
public static void main (String args[]) throws Exception
{
DOMParser parser;
XMLDocument xml, xsldoc, out;
URL xslURL;
URL xmlURL;
try
{
if (args.length != 2)
{
// Pass in the names of the XSL and XML files
System.err.println("Usage: java XSLTransform
xslfile xmlfile");
System.exit(1);
}
// Parse XSL and XML documents
parser = new DOMParser();
parser.setPreserveWhitespace(true);
xslURL = createURL(args[0]);
parser.parse(xslURL);
xsldoc = parser.getDocument();
xmlURL = createURL(args[1]);
parser.parse(xmlURL);
xml = parser.getDocument();
// Instantiate the stylesheet
XSLStylesheet xsl = new XSLStylesheet(xsldoc, xslURL);
XSLProcessor processor = new XSLProcessor();
// Display any warnings that may occur
processor.showWarnings(true);
processor.setErrorStream(System.err);
// Process XSL
DocumentFragment result = processor.processXSL(xsl, xml);
// Create an output document to hold the result
out = new XMLDocument();
// Create a dummy document element for the output document
Element root = out.createElement("root");
out.appendChild(root);
// Append the transformed tree to the dummy document element
root.appendChild(result);
// Print the transformed document
out.print(System.out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
XML Class Generator for
Java
The XML Class Generator for Java creates Java source
files from an XML DTD or XML Schema. This is useful when an application
wants to send an XML message to another application based on an agreed-upon
DTD or Schema, or as the back end of a Web form to construct and XML document.
Using these classes, Java applications can construct, validate, and print
XML documents that comply with the input DTD or Schema. The Class Generator
works in conjunction with the Oracle XML Parser for Java, which parses
the DTD or Schema and passes the parsed document to the class generator.

Example: XML Class Generator For Java
This example shows how the XML Class Generator for
Java can be used to process a DTD and generate classes for the DTD's elements.
It then shows how to programmatically use methods of the element classes
to construct a valid XML document.
The Input DTD
The following DTD file for employee data, employee.dtd,
is used as the input to the class generator. Here, the DTD specifies that
the XML document root is EMP and the row element is EMP_ROW. EMP consists
of one or more EMP_ROWs. Each EMP_ROW contains a required EMPNO attribute
for the employee number, as well as several optional attributes such as
ENAME for employee names, JOB for job type, MGR for manager, and so on.
Optional attributes are followed by a "?" in the element definition. The
definitions of EMPNO, ENAME, and the other EMP_ROW elements state that
the elements contain plain character data (PCDATA).
<!-- DTD for Employee Data -->
<!ELEMENT EMP (EMP_ROW)*>
<!ELEMENT EMP_ROW (EMPNO, ENAME?, JOB?, MGR?, HIREDATE?, SAL?,
COMM?, DEPTNO?)>
<!ATTLIST EMP_ROW ROWNO CDATA #REQUIRED>
<!ELEMENT EMPNO (#PCDATA)>
<!ELEMENT ENAME (#PCDATA)>
<!ELEMENT JOB (#PCDATA)>
<!ELEMENT MGR (#PCDATA)>
<!ELEMENT HIREDATE (#PCDATA)>
<!ELEMENT SAL (#PCDATA)>
<!ELEMENT COMM (#PCDATA)>
<!ELEMENT DEPTNO (#PCDATA)>
Processing the DTD to Generate Java Classes
The following code sample processes a DTD and generates
the corresponding classes for elements in the DTD. Running the class generator
on the DTD above (employee.dtd) creates Java classes for each
element (EMP, EMP_ROW, EMPNO, ENAME, and so on). A Java application can
then use the methods defined on these classes to create a valid XML document
containing employee data.
import java.io.*;
import java.net.*;
import oracle.xml.parser.*;
import oracle.xml.classgen.*;
import org.w3c.dom.Element;
public class SampleMain
{
public SampleMain()
{
}
public static void main (String args[])
{
// validate arguments
if (args.length < 1)
{
System.out.println("Usage: java SampleMain "+
"[-root <rootName>] <fileName>");
System.out.println("fileName\t Input file, XML document or " +
"external DTD file");
System.out.println("-root <rootName> Name of the root Element " +
"(required if the input file is an external DTD)");
return ;
}
try // to open the External DTD File
{
// instantiate the parser
XMLParser parser = new XMLParser();
if (args.length == 3)
parser.parseDTD(fileToURL(args[2]), args[1]);
else
parser.parse(fileToURL(args[0]));
XMLDocument doc = parser.getDocument();
DTD dtd = (DTD)doc.getDoctype();
String doctype_name = null;
if (args.length == 3)
{
doctype_name = args[1];
}
else
{
// get the Root Element name from the XMLDocument
doctype_name = doc.getDocumentElement().getTagName();
}
// generate the Java files...
ClassGenerator generator = new ClassGenerator();
// set generate comments to true
generator.setGenerateComments(true);
// set output directory
generator.setOutputDirectory(".");
// set validating mode to true
generator.setValidationMode(true);
// generate java src
generator.generate(dtd, doctype_name);
}
catch (Exception e)
{
System.out.println ("XML Class Generator: Error " + e.toString());
e.printStackTrace();
}
}
static public URL fileToURL(String sfile)
{
File file = new File(sfile);
String path = file.getAbsolutePath();
String fSep = System.getProperty("file.separator");
if (fSep != null && fSep.length() == 1)
path = path.replace(fSep.charAt(0), '/');
if (path.length() > 0 && path.charAt(0) != '/')
path = '/' + path;
try
{
return new URL("file", null, path);
}
catch (java.net.MalformedURLException e)
{
// Can only happen if the file
// protocol were not recognized
throw new Error("unexpected MalformedURLException");
}
}
}
Creating a Valid XML Document from Java Classes
The following Java code shows how generated methods
might be used. Here, two row elements are created: emp_row1 and emp_row2.
Elements for each column are also created (empno1, ename1, and so on).
To build an XML document tree, the various data elements are grouped by
assigning them to each row element as tree nodes. Each row element is then
added as a node to the document root element EMPLIST. In this example,
names of classes generated by the class generator are in uppercase:
import oracle.xml.classgen.*;
import oracle.xml.parser.*;
public class CreateEmployees
{
public static void main (String args[])
{
try
{
EMP EMPLIST = new EMP();
DTD dtd = EMPLIST.getDTDNode(); // get static from base document
// New employee emp_row1
EMP_ROW emp_row1 = new EMP_ROW(1); // create row and set ROWNO
EMPNO empno1 = new EMPNO("7654");
ENAME ename1 = new ENAME("MARTIN");
JOB job1 = new JOB("SALESMAN");
MGR mgr1 = new MGR("7698");
HIREDATE hiredate1 = new HIREDATE("1981-09-28 00:00:00.0");
SAL sal1= new SAL("1250");
COMM comm1= new COMM("1400");
DEPTNO deptno1 = new DEPTNO("30");
// New employee emp_row2
EMP_ROW emp_row2 = new EMP_ROW(2); // create row and set ROWNO
EMPNO empno2 = new EMPNO("7788");
ENAME ename2 = new ENAME("SCOTT ");
JOB job2 = new JOB("ANALYST ");
MGR mgr1 = new MGR("7566");
HIREDATE hiredate2 = new HIREDATE("1987-04-19 00:00:00.0");
SAL sal2= new SAL("3000");
COMM comm2= new COMM("");
DEPTNO deptno2 = new DEPTNO("20");
emp_row1.addnode(empno1); // Add data as tree nodes to emp_row1
emp_row1.addnode(ename1);
...
emp_row2.addnode(empno2); // Add data as tree nodes to emp_row2
emp_row2.addnode(ename2);
...
EMPLIST.addNode(emp1); // Add emp_row1 as tree node to
// EMPLIST doc root
EMPLIST.addNode(emp2); // Add emp_row2 as tree node to
// EMPLIST doc root
EMPLIST.validateContent();
EMPLIST.print(System.out);
}
catch (Exception e)
{
System.out.println(e.toString());
e.printStackTrace();
}
}
}
XML Document Created by Java Application
The Java application above creates an XML document
similar to the following:
<?xml version="1.0"?>
<!DOCTYPE EMP SYSTEM "employee.dtd">
<EMP>
<EMP_ROW ROWNO = "1">
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-09-28 00:00:00.0</HIREDATE>
<SAL>1250</SAL>
<COMM>1400</COMM>
<DEPTNO>30</DEPTNO>
/EMP_ROW>
<EMP_ROW ROWNO = "2">
<EMPNO>7788</EMPNO>
<ENAME>SCOTT</ENAME>
<JOB>ANALYST</JOB>
<MGR>7566</MGR>
<HIREDATE>1987-04-19 00:00:00.0</HIREDATE>
<SAL>3000</SAL>
<COMM></COMM>
<DEPTNO>20</DEPTNO>
</EMP_ROW>
</EMP>
XML SQL Utility for Java
The XML SQL Utility for Java consists of a set of
Java classes that:
-
Pass a query to the database and generate an XML
document (text or DOM) from the results.
-
Write XML data to a database table.
Generating XML from Query Results
As shown in the following figure, the XML SQL Utility
can process SQL queries and return the results as an XML document.
The structure of the resulting XML document is
based on the internal structure of the database schema that returns the
query results. Columns are mapped to top level elements. Scalar values
are mapped to elements with text-only content. Object types are mapped
to elements with attributes appearing as sub-elements. Collections are
mapped to lists of elements. Object references and referential constraints
are mapped to XML IDREFs.
The utility can generate either a string representation
of the XML document, or an in-memory XML DOM tree of elements. If you are
returning the XML document to a requester, the string representation is
best. You should use the DOM representation if you are going to operate
on the XML programmatically, for example, transform it using the XSLT Processor
or use DOM methods to search or modify the XML in some way.
You can also use the XML SQL Utility to generate
a DTD based on the schema of the underlying table being queried. You can
use the generated DTD as input to the XML Class Generator for Java, which
will generate a set of classes based on the DTD elements. You can then
write Java code that use these classes to generate the infrastructure behind
a web-based form. Based on this infrastructure, the web form will capture
user data and create an XML document compatible with the database schema.
This data can then be written directly to the corresponding database table
or object view without further processing. For more information about this
approach, see Exchanging Data Among
Applications.
Example: Generating XML from Query Results
The following is simple example of using the XML
SQL Utility to create an XML document from a query. Submitting the following
query to the utility:
SELECT EMPNO, ENAME FROM EMP WHERE EMPNO = 7654;
generates the following XML document:
<?xml version="1.0"?>
<ROWSET>
<ROW id="1">
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
</ROW>
</ROWSET>
Note the format of the XML document. By default,
ROWSET is the element name of the XML document element. ROW is the element
name for each row in the query result. Data such as EMPNO and ENAME are
also represented as elements nested within the ROW node. In general, data
is represented as elements and attributes are used to constrain the data
where needed. Should an application require a different set of tags, an
XSL stylesheet can perform the transformation dynamically.
Example: Generating XML from Query Results and Structuring
the Data
Using the XML SQL Utility's API, you can also constrain
the data presented in the XML document. For example, you can specify things
like the maximum number of rows to return, the number of rows to be skipped,
what XSL stylesheet to use, among others.
The following Java code queries the database and
constructs an XML file containing the results. The query is a simple select
EMPNO, ENAME from EMP:
import java.sql.*;
import java.math.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.*;
import oracle.jdbc.driver.*;
public class xmlquerydb
{
public static void main(String args[]) throws SQLException
{
String tabName = "emp";
String user = "scott/tiger";
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//initiate a JDBC connection
Connection conn =
DriverManager.getConnection("jdbc:oracle:oci8:"+user+"@");
// initialize the OracleXMLQuery
OracleXMLQuery qry = new OracleXMLQuery(conn,"select EMPNO,
ENAME from "+tabName );
// structure the generated XML document
qry.setMaxRows(2); // set the maximum number of rows to be returned
qry.setRowsetTag("ROOTDOC"); // set the root document tag
qry.setRowTag("DBROW"); // sets the row separator tag
qry.setStyleSheet("emp.xsl"); // sets the stylesheet
// get the XML document in string format
String xmlString = qry.getXMLString();
// print out the XML document
System.out.println(" OUTPUT IS:\n"+xmlString);
}
}
The resulting XML file returns the first two rows
found in the EMP table:
<?xml version="1.0"?>
<ROOTDOC>
<DBROW id="1">
<EMPNO>7876</EMPNO>
<ENAME>ADAMS</ENAME>
</DBROW>
<DBROW id="2">
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
</DBROW>
</ROOTDOC>
Writing XML to a Table
As shown in the following figure, you can use the
XML SQL Utility to write XML data to an Oracle8i object-relational
database table.

Storing an XML document in an Oracle8i
table preserves the structure of the document. Element tag names are mapped
to column names in the table. Elements with text-only content are mapped
to scalar columns, and elements containing sub-elements are mapped to object
types. Lists of elements are mapped to collections. Unstructured data like
textual comments or descriptions cannot be mapped to underlying database
tables, so this kind of data should be stored as a CLOB in the database.
See Oracle8i and interMedia documentation for more information.
Example: Writing XML to a Table
The following Java code inserts the data from the
XML file emp.xml into the EMP table. This example assumes the
XML document already conforms to the structure of the EMP table.
import oracle.xml.sql.dml.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.*;
import java.net.*;
public class xmlwritedb
{
public static void main(String args[]) throws SQLException
{
String tabName = "EMP"; // Table into which to insert XML data
String fileName = "emp.xml"; // XML document filename
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Initialize a JDBC connection
Connection conn =
DriverManager.getConnection("jdbc:oracle:oci8:scott/tiger@");
// Insert XML data from file (filename) into
// database table (tabName)
OracleXMLSave save = new OracleXMLSave(conn, tabName);
URL url = save.createURL(fileName);
int rowCount = save.insertXML(url);
System.out.println(" successfully inserted "+rowCount+
" rows into "+ tabName);
conn.close();
}
}
Note, that if you want to write an XML document to
a database table, but the XML data does not match the underlying table
structure, you need to transform the XML document before writing it to
the database. For techniques on doing this, see Exchanging
Data Among Applications.
XSQL Servlet
The XSQL Servlet is a tool that processes SQL queries
and outputs the result set as XML. This processor is implemented as a Java
servlet and takes as its input an XML file containing embedded SQL queries.
It uses the XML Parser for Java and the XML SQL Utility to perform many
of its operations.
You can run this servlet in any web server that
supports Java servlets. The following figure shows how data flows from
a client, to the servlet, and back to the client. The sequence of events
is as follows:
-
The user enters a URL through a browser, which is
interpreted and passed to the XSQL Servlet through a Java Web Server. The
URL contains the name of the target XSQL file (.xsql) and optionally, parameters,
such as values and an XSL stylesheet name. Alternatively, the user can
invoke the XSQL Servlet from the command line, bypassing the browser and
Java web server.
-
The servlet passes the XSQL file to the XML Parser
for Java, which parses the XML and creates an API for accessing the XML
contents.
-
The page processor component of the servlet uses
the API to pass XML parameters and SQL statements (found between <query></query>
tags) to the XML SQL Utility. The page processor also passes any XSL processing
statements to the XSLT Processor.
-
The XML SQL Utility sends the SQL queries to the
underlying Oracle8i database, which returns the query results to
the utility.
-
The XML SQL Utility returns the query results to
the XSLT Processor as XML formatted text. The results are embedded in the
XML file in the same location as the original <query> tags.
-
If desired, the query results and any other XML data
are transformed by the XSLT Processor using a specified XSL stylesheet.
The data can be transformed HTML or any other format defined by the stylesheet.
The XSLT Processor can selectively apply different stylesheets based on
the type of client that made the original URL request. This HTTP_USER_AGENT
information is obtained from the client through an HTTP request.
-
The XSLT Processor passes the completed document
back to the client browser for presentation to the user.
Example: XSQL Servlet
The following is a simple XSQL file that queries
an employee table EMP. The default behavior of the query is to return all
employee rows in the table. Optionally, you can narrow the search by adding
a find= URL parameter when calling the XSQL servlet from the browser. For
example, specifying the letter 'T' as the find value will return only those
rows whose ENAME contains the letter T. Also, you can sort the returned
rows by specifying a sort= URL parameter. For example, specifying EMPNO
will sort the rows by employee number.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="rowcol.xsl"?>
<query connection="demo"
find="%"
sort="ENAME"
null-indicator="yes" >
SELECT * FROM EMP
WHERE ENAME LIKE '%{@find}%'
ORDER BY {@sort}
</query>
The XSQL file also specifies that the returned results
should be processed using the XSL stylesheet rowcol.xsl. This stylesheet
is as follows.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/technology/">
<html>
<body class="page">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="ROWSET">
<center>
<table border="0" cellpadding="4">
<xsl:choose>
<xsl:when test="ROW">
<!-- present headings: row[1] columns +-->
<xsl:for-each select="ROW[1]">
<tr>
<xsl:for-each select="*">
<th align="left">
<xsl:attribute name="class">
</xsl:attribute>
<xsl:value-of select="name(.)"/>
</th>
</xsl:for-each>
</tr>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<tr><td>No Matches</td></tr>
</xsl:otherwise>
</xsl:choose>
</table>
</center>
</xsl:template>
<!-- present rows and columns +-->
<xsl:template match="ROW">
<tr>
<xsl:attribute name="class">
</xsl:attribute>
<xsl:for-each select="*">
<td>
<xsl:attribute name="class">
</xsl:attribute>
<xsl:apply-templates select='.'/>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
The figure below shows the HTML page that is generated
by the XSQL Servlet using the XSQL file emp.xsql and the rowcol.xsl
stylesheet. This servlet was invoked using the following URL:
http://localhost/xsql/demo/emp.xsql?find=T&sort=EMPNO
| EMPNO |
ENAME |
JOB |
MGR |
HIREDATE |
SAL |
COMM |
DEPTNO |
| 7654 |
MARTIN |
SALESMAN |
7698 |
1981-09-28 00:00:00.0 |
1250 |
1400 |
30 |
| 7788 |
SCOTT |
ANALYST |
7566 |
1987-04-19 00:00:00.0 |
3000 |
|
20 |
| 73369 |
SMITH |
CLERK |
7902 |
1980-12-17 00:00:00.0 |
800 |
20 |
| 7844 |
TURNER |
SALESMAN |
7698 |
1981-09-08 00:00:00.0 |
1500 |
0 |
30 |
XML Transviewer Java
Beans
The XML Transviewer Beans are a set of XML components
for Java applications or applets. These visual and non-visual Java components
can be integrated into Oracle JDeveloper to enable developers to create
and deploy XML-based database applications quickly. The following beans
are available:
-
DOM Builder Bean
-
XML Source Viewer Bean
-
XML Tree Viewer Bean
-
XSL Transformer Bean
DOM Builder Bean
The DOM Builder Bean encapsulates the Java XML Parser
with a bean interface and extends its functionality to permit asynchronous
parsing. By registering a listener, Java applications can parse large or
successive documents having control return immediately to the caller.
XML Source Viewer Bean
The XML Source View Bean improves the viewing of
XML and XSL files by color-highlighting XML/XSL syntax. This is usefule
when modifying an XML document with an editing application. Easily integrated
with the DOM Builder Bean, it allows for pre or post parsing and validation
against a specified DTD.
XML Tree Viewer Bean
The XML Tree View Bean displays a visual view of
an XML document, enabling users to easily manipulate the tree with a mouse
to hide or view selected branches.
XSL Transformer Bean
The XSL Transformer Bean enables users to transform
an XML document to almost any text-based format including XML, HTML and
DDL, by applying an XSL stylesheet. When integrated with other beans, this
bean enables an application or user to view the results of transformations
immediately. This bean can also be used as the basis of a server-side application
or servlet to render an XML document, such as an XML representation of
a query result, into HTML for display in a browser.
XML Schema Processor
The XML Schema Procesor parses and validates XML
files, offering features and functionality beyond what is provided by DTDs.
As defined by the W3C, "XML Schemas express shared vocabularies and allow
machines to carry out rules made by people." The Oracle XML Schema Processor
supports the three parts of the W3C XML Schema Working Draft:
XML Schema are also at the core of the native XML
support in the Oracle9i database, letting developers easily and
seamlessly manipulate complex XML e-business data using Java and SQL, so
Oracle customers benefit from the very latest open XML standards.
Oracle9i Product Family
Oracle9i
can store XML in the database via SQL and render traditional database
data as XML. The areas of XML support in Oracle9i include:
-
Built-in, native functions linked to the Oracle9i
kernel for generating XML. Three new, highly-scalable PL/SQL functions
(SYS_XMLGEN, SYS_XMLAGG, and DBMS_XMLGEN) provide an alternative to the
XDK for working within the database to generate XML.
-
Native XML type support. For applications that need
to store and retrieve large amounts of complex XML, Oracle9i stores
XML natively by introducing XMLType, a new object datatype, and features
extremely fast, navigational access and searches for XML documents.
-
The UriType family of types can store and query URI-refs
in the database. SYS.UriType is an abstract object type that provides functions
to access the data pointed to by the URL. SYS.HttpUriType and SYS.DBUriType
are subtypes of UriType. The HttpUriType can store HTTP URLs and the DBUriType
can store intra-database references.
-
New Oracle Text XML-searching capabilities including
new operators HASPATH and INPATH that leverage XPath expressions within
Oracle Text queries. You can use Oracle Text to perform searches on XML
documents stored in Oracle9i by indexing the XML as plain text,
or as document sections for more precise searches, such as find "Oracle
WITHIN title" where "title" is a section of the document.
-
Oracle Advanced Queuing (AQ) uses XML to provide
infrastructure for e-business integration. Specifically, AQ defines a presentation
named iDAP (Internet Data Access Presentation) using XML. With iDAP, AQ
operations can be executed via Internet transport protocols such
as HTTP(S), SMTP, and FTP. AQ supports XML datatype payloads and allows
definitions of subscriptions based on contents of XML messages.
These features support the focus areas of B2B and
B2C eBusiness, Packaged Applications, and Internet Content Management.
They enable developers to work with XML seamlessly within a traditional
relational context or pure XML context yet fully leverage the inherent
scalability, managability and reliability characteristics of the Oracle9i
Database.
XML in the Database
The basic strategies for storing XML documents in
the database are:
-
Storing an XML document as a single, intact object
with its tags in a CLOB or BLOB.
-
Storing an XML document as data and distributing
it untagged across object-relational tables.
-
Combining XML documents and data using views.
Depending on the structure of the XML document, you
may choose one of these approaches.
Storing XML Documents as CLOBs or BLOBs
Storing an intact XML document in a CLOB or BLOB
is a good strategy if the XML document contains static content that will
only be updated by replacing the entire document. Examples include written
text such as articles, advertisements, books, legal contracts, and so on.
Documents of this nature are known as document-centric and are delivered
from the database as a whole. Storing this kind of document intact within
Oracle9i gives you the advantages of an industry-proven database
and its reliability over file system storage. If you choose to store an
XML document outside of the database, you can still use Oracle9i features
to index, query, and efficiently retrieve the document through the use
of BFILES, URLs, and text-based indexing.
Storing XML Documents as Data
If the XML document has a well-defined structure
and contains data that is updateable or used in other ways, the document
is data-centric. Typically, the XML document contains elements or attributes
that have complex structures. Examples of this kind of document include
sales orders and invoices, airline flight schedules, and so on. With its
object-relational extensions, Oracle9i
has the ability to capture
the structure of the data in the database using object types, object references,
and collections. There are two options for storing and preserving the structure
of the XML data in an object-relational form:
-
Store the attributes of the elements in a relational
table and define object views to capture the structure of the XML elements.
-
Store the structured XML elements in an object table.
Once stored in the object-relational form, the data
can be easily updated, queried, rearranged, and reformatted as needed using
SQL.
The XML SQL Utility provides the means to then
store an XML document by mapping it to the underlying object-relational
storage, and conversely, provides the ability retrieve the object-relational
data as an XML document.
If an XML document is structured, but the structure
of the XML document is not compatible with the structure of the underlying
database schema, you must transform the data into the correct format before
writing it to the database. You can achieve this using XSL stylesheets
or other programming approaches, but depending on your needs, you might
want to store the data-centric XML document as an intact single object.
Alternately, you can define object views corresponding to the various XML
document structure and define instead-of triggers to perform the appropriate
transformation and update the base data.
Combining XML Documents and Data Using Views
Finally, if you have a combination of structured
and unstructured XML data, but still want to view and operate on it as
a whole, you can use views. Views enable you to construct an object on
the "fly" by combining XML data stored in a variety of ways. So, you can
store structured data (such as employee data, customer data, and so on)
in one location within object -relational tables, and store related unstructured
data (such as descriptions and comments) within a CLOB. When you need to
retrieve the data as a whole, you simply construct the structure from the
various pieces of data with the use of type constructors in the view's
select statement. The XML SQL Utility then enables retrieving the constructed
data from the view as a single XML document.
Oracle Internet File System
The Oracle Internet File
System XML Framework depends largely on parsing; that is, the orderly
dissection of a file when it is inserted into the repository. Properly
parsed, these elements can be stored in the database as attributes, for
later reassembly. XML files can also be used to perform system configuration
tasks, such as creating user accounts. Finally, XML files can be stored
without any parsing at all. The parsing framework included in the Oracle
Internet File System provides for a wide range of use cases, including
support for identifying new document types and applying configurable parsing
logic to them.
Many development tasks can be done using XML alone.
Since the entire API is exposed and documented, advanced file system and
content management features are readily available to developers. Here are
some examples of development projects that the Oracle Internet File System
makes possible:
-
Extend XML support to create new XML Applications.
-
Build a documentation suite that uses XML.
-
Create custom parsers and renderers to manipulate
documents according to your business problem set.
-
Build a custom parser that renders Word files containing
graphics as PDFs, and renders Word files containing XML spreadsheets as
HTML files.
-
Invoke new presentation methods for specific file
types.
-
Build a custom parser that associates files with
one of several custom rendererers based on custom attributes within the
files.
-
Design and implement security schemes using XML.
Create an XML template to streamline the process
of adding new user accounts in several applications and folders.
Oracle9i AS Product Family
Configured out of the box to support the XDK, Oracle9i
Application Server (Oracle9iAS) delivers the flexibility to
deploy Web sites and XML-enable applications. Oracle extends this flexibility
throughout the Oracle9i AS product family.
Oracle9iAS Forms Services
Oracle9iAS Forms
Services provides a comprehensive application framework for deploying
enterprise-class applications on the Internet. Through open APIs, you can
leverage XML as part of the business-to-business communication required
with every new e-business application.
Oracle9iAS Portal
Oracle9iAS Portal
(formerly called WebDB), is an enterprise-level e-business portal, connecting
the worlds of dynamic data, documents, and Web sites via re-usable information
components called portlets. A portlet is a live area of HTML or
XML/XSL which represents an information source in a standardized, consistent,
and secure manner. You can think of portlets as Web components that display
excerpts form other Web sites and generate summaries of key information.
Portlets can be placed on the same page with other portlets so users have
easy access to frequently used sites and information.
Oracle9iAS Wireless Edition
Oracle9iAS Wireless
Edition (formerly called Portal-to-Go) uses XML and XSL to dynamically
transform Internet content to various mobile device formats, including
PDAs, Windows CE devices, and mobile phones. Oracle9iAS Wireless
Edition converts Internet content to a generic XML format, and then uses
XSL to transform the data into generic HTML or device-specific formats,
including WML for mobile phones, HDML, TTML, or VoxML for IVR (Interactive
Voice Response) systems.

Oracle Reports
Oracle Reports provides a powerful development and
deployment platform to build and publish high-quality, dynamically-generated
Web reports in a scalable, secure environment. Reports can be published
throughout the enterprise via a standard Web browser, in a wide range of
formats, including XML.
Oracle Internet Developer
Suite
Oracle Internet Developer
Suite combines the power of Oracle Application Development tools, Oracle
Business Intelligence tools, and Oracle Portal Building tools in a single
box. Based on Internet standards like Java, XML, EJB, and CORBA, it provides
a highly productive environment for building applications.
For example, Oracle Internet Developer Suite includes
Oracle
JDeveloper, which uses XML internally and enables development of XML
applications. JDeveloper offers many features that enable developers to
create business-to-consumer and business-to-business XML applications.
JDeveloper can be utilized to write XML documents and XSL Stylesheets,
to generate XML on the fly using the Business Components for Java Framework
or the database directly and to transform XML into HTML, WML, XML or any
other format. JDeveloper integrates the various XML Utilities that Oracle
has produced, including the Oracle XML Parser for Java, the XML SQL Utility
and the XSQL Servlet. JDeveloper provides an integrated development environment
for developers by offering editors, compilers and (remote) debuggers for
Java and XML.
Internally, the Business
Components for Java Framework uses XML to store metadata about its
application components. Important information is stored in a structured
document rather than in Java source code. This makes applications easier
to customize, because you don't need access to the Java source code.
Oracle E-Business Suite
XML plays an important role in Oracle applications,
as well. Open XML standards streamline the connection of business processes
both within the Oracle E-Business
Suite and with third-party software applications. The Oracle E-Business
Suite�commonly referred to as Release 11i�simplifies the integration
process by coordinating all key business functions across the extended
enterprise�from marketing and sales to manufacturing, order processing,
fulfillment, and customer service. Because XML is the de facto standard
for B2B communications, companies using Oracle E-Business Suite can tap
into B2B marketplaces and communicate easily with trading partners.
As a key component of Oracle's application integration
framework, XML Messaging Services comprise an event-driven, standards-based
solution for exchanging and integrating XML messages within the Oracle
E-Business Suite. For example, in the Oracle Order Management application,
the interfaces for invoices, ship notices, purchase orders, and other business
object documents (BODs) are all converted to XML. Similarly, in manufacturing
and supply chain applications, XML transactions communicate specifications
to a subcontractor or component manufacturer.
OTN as Developer Service Provider
Oracle Technology Network (OTN) is an industry-first
Developer Service Provider (DSP) that offers free, online hosted studios
for developing, testing and deploying Oracle9i-based solutions.
OTN developer services include an online workplace environment for collaborative
development, online support with access to Oracle and industry experts,
as well as free software downloads, technical libraries and a job marketplace
for Oracle-related positions. Two important areas of the development environment
are OracleMobile Online Studio and Oracle Portal Studio; both areas leverage
XML.
OracleMobile Online Studio
OracleMobile
Online Studio is an online environment for building, testing, and deploying
applications for mobile devices regardless of network, protocol, or markup
language. Online Studio presents a hosted approach to developing dynamic
content. You do not need to download any software or tools to start using
Online Studio. When you log in, you have access to reusable modules, examples,
documentation, runtime information, and other useful resources. OracleMobileOnline
Studio requires only a HTTP URL link to your mobile application. Your application
logic is actually hosted by your own servers. OracleMobileOnline Studio
makes standard HTTP requests to your servers to retrieve the MobileXML
content. The business logic of your application is entirely in your control
and transparent to OracleMobileOnline Studio.
XML is a key technology, enabling Online Studio
to support multiple wireless device formats. Software modules called transformers
use XSL and device-specific processing to optimize layout for each device
type. Transformers are updated and maintained rigorously to maintain compatibility
with the device market.
Oracle Portal Studio
Oracle
Portal Studio is a hosted development environment offering all the
resources you need�including the Portal Development Kit (PDK), discussion
forum, guidelines, examples, and a registration wizard�to build portlets,
test them, and make them available to other users.
XML plays an important role in the Portal Studio
and the PDK. For example, applications called providers parse XML
documents for data, including properties such as location and implementation
details, about the portlets they provide.
Questions or comments? Post a message in OTN's
XML discussion
forum.
Using XML in Oracle Database Applications:
Part 2: About Oracle XML Products
Author: Brad Wait, Oracle Corporation
Date: November 1999. Updated June
2001 by Robert Hall, Oracle
Corporation.
This document is provided for information
purposes only and the information herein is subject to change without notice.
Please report any errors herein to Oracle Corporation. Oracle Corporation
does not provide any warranties covering and specifically disclaims any
liability in connection with this document.
Oracle is a registered trademark
and Enabling the Information Age is a trademark or registered trademark
of Oracle Corporation. All other company and product names mentioned are
used for identification purposes only and may be trademarks of their respective
owners.
Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA94065
U.S.A.
Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation
1999, 2000, 2001
All Rights Reserved
|