Oracle® Application Developer's Guide - XML 10g (9.0.4) Part Number B12099-01 |
|
This chapter contains the following sections:
This chapter provides an overview of Oracle's XML components.
Oracle provides several components, utilities, and interfaces you can use to take advantage of XML technology in building your Web-based database applications. Which components you use depends on your application requirements, programming preferences, development, and deployment environments.
The following XML components are provided with Oracle and Oracle Application Server:
The following figures schematically illustrate how the XDK components can be used to generate XML:
Table 3-1 XDK Component Descriptions
The following list includes Oracle's XML-enabled development tools:
XDK for Java is composed of the following components:
XDK for Java Beans is composed of the following component:
XDK for C is composed of the following component:
XDK for C++ is composed of the following:
XDK for PL/SQL is composed of the following:
The Oracle XML parser includes implementations in C, C++, PL/SQL, and Java for the full range of platforms on which Oracle Database runs.
Based on conformance tests, xml.com
ranked the Oracle parser in the top two validating parsers for its conformance to the XML 1.0 specification, including support for both SAX and DOM interfaces. The SAX and DOM interfaces conform to the W3C recommendations 2.0.
Version 2 (v2) of the Oracle XML parser provides integrated support for the following features:
The parsers are available on all Oracle platforms.
Figure 3-1 illustrates the Oracle XML Parser for Java. Figure 3-2 illustrates the Oracle XML parsers' overall functionality.
The Oracle XSLT engine fully supports the W3C 1.0 XSL Transformations recommendation. It has the following features:
The Oracle XML Parsers, Version 2 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.
How to use the XSLT Processor is described in Chapter 20, "Using XML Parser for Java".
XML Class Generator creates a set of Java or C++ classes for creation of XML documents corresponding to an input DTD or XML Schema. Figure 3-3 shows Oracle XML Class Generator functionality.
How to use the XML Class Generators is described in the following chapters:
Oracle XML Transviewer Java Beans are a set of XML components that constitute XML for Java Beans. These are used for Java applications or applets to view and transform XML documents.
They are visual and non-visual Java components that are integrated into Oracle JDeveloper to enable the fast creation and deployment of XML-based database applications. In this release, the following four beans are available:
As standard Java Beans, they can be used in any graphical Java development environment, such as Oracle JDeveloper. The Oracle XML Transviewer Beans functionality is described in Chapter 23, "Using XML Transviewer Beans".
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 XML Parser for Java, XML- SQL Utility, and Oracle XSL Transformation (XSLT) Engine to perform many of its operations.
You can use XSQL Servlet to perform the following tasks:
XSQL Servlet has been tested with the following servlet engines:
JavaServer Pages can use <jsp:forward>
or <jsp:include>
to collaborate with XSQL Pages as part of an application. The following JSP platforms have been tested to support XSQL Servlet:
In general, it should work with the following:
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 XML Parser for Java and XML SQL Utility to perform many of its operations.
Figure 3-4 shows how data flows from a client, to the servlet, and back to the client. The sequence of events is as follows:
<query></query>
tags) to XML SQL Utility. The page processor also passes any XSL processing statements to the XSLT Processor.
<query>
tags.
HTTP_USER_AGENT
information is obtained from the client through an HTTP request.
Oracle XML SQL Utility (XSU) supports Java and PL/SQL.
XML SQL Utility Java classes can be used for the following tasks:
Figure 3-5 shows the Oracle XML SQL Utility overall functionality.
XML SQL Utility for Java consists of a set of Java classes that perform the following tasks:
Figure 3-6 shows how XML SQL Utility processes SQL queries and returns 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:
The XML SQL Utility (XSU) generates either of the following:
You can also use the XML SQL Utility (XSU) to generate a DTD based on the schema of the underlying table or view being queried. You can use the generated DTD as input to the XML Class Generator for Java or C++. This generates a set of classes based on the DTD elements. You can then write code that uses these classes to generate the infrastructure behind a Web-based form. See also "XML Class Generator".
Based on this infrastructure, the Web form can 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.
See Also:
Chapter 7, "XML SQL Utility (XSU)" and Oracle9i Case Studies - XML Applications, the chapter, "B2B XML Application: Step by Step", for more information about this approach. |
Note: To write an XML document to a database table, where the XML data does not match the underlying table structure, transform the XML document before writing it to the database. For techniques on doing this, see Chapter 7, "XML SQL Utility (XSU)". |
Oracle Text (interMedia Text) extends Oracle Database by indexing any text or documents stored in Oracle. Use Oracle Text to perform searches on XML documents stored in Oracle 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.
See Also:
Chapter 8, "Searching XML Data with Oracle Text", for more information on using Oracle Text and XML. |
Figure 3-7 through Figure 3-10 illustrate the relationship of the Oracle XML components and how they work together to generate XML documents from Oracle via a SQL query. The options are depicted according to language used:
Figure 3-7 shows the Oracle XML Java components and how they can be used to generate an XML document. Available XML Java components are:
In the Java environment, when a user or client or application sends a query (SQL), there are three possible ways of processing the query using the Oracle XML components:
Regardless of which way the stored XML data is generated from the database, the resulting XML document output from the XML Parser is further processed, depending on what you or your application needs it for.
The XML document is formatted and customized by applying stylesheets and processed by the XSLT.
Figure 3-8 shows the Oracle XML C language components used to generate an XML document. The XML components are:
SQL queries can be sent to the database via OCI or as embedded statements in the Pro*C precompiler.
The resulting XML data can be processed in the following ways:
This XML data is optionally transformed by the XSLT processor, viewed directly by an XML-enabled browser, or sent for further processing to an application or AQ Broker.
Figure 3-9 shows the Oracle XML components used to generate an XML document. The XDK for C++ components used here are:
In the C++ environment, when a user or client or application sends a SQL query, there are two possible ways of processing the query using the XDK for C++:
Figure 3-10 shows the XDK for PL/SQL components used to generate an XML document:
In the PL/SQL environment, when a user or client or application sends a SQL query, there are two possible ways of processing the query using the Oracle XML components:
This section includes general questions about Oracle XML-enabled technology in the following categories:
There are Frequently Asked Questions at the end of several other chapters in this manual.
I am going to develop a small application using XML and Oracle. Here is the scenario: Company A has is a central purchasing system with Departments B, C, and D. Company A gets purchase orders in XML format from B, C, and D.
Company A needs to collect all purchase orders and store them in an Oracle database. Then, it has to create another Request for proposal for its preferred vendors in XML. I am writing queries to insert or update into the database. What XML components do I need to install in Oracle?
Assuming you are using Java, you need the XML Parser and XML SQL Utility. If you are using a Java-based front end to generate the purchase orders, then the XML Class Generator can provide you with the classes you need to populate your purchase orders. Finally, the XSQL Servlet can help you build a Web interface.
I have a CGI-PERL-Oracle7 application on Solaris 2.6 and I want to convert it to XML/XSL-JAVA-Oracle. I know most parts of the technologies, for example, SGML, XML, and JAVA, but I don't know how to start it in Oracle. What software do I need from Oracle? Specifically,
UTL_HTTP
?
Is there a tool that goes from a DTD to a database schema?
Currently we do not have a tool to go from a DTD to a database schema as there is no way to specify datatypes until we have XML Schema. With our XML- SQL Utility available on OTN with our other XML components you can generate a DTD from a database schema which can then be entered into the Class Generator. You should try an approach your solution from that angle since a database is involved. Check out our OTN resource including the XML Discussion Forum for further assistance at http://otn.oracle.com/tech/xml
My project requires converting master-details data to XML for clients.
Are there any utilities in the XDK that translate data from a given format to XML? I know that the XSLT will translate from XML to XML, HTML, or another text-based format. What about the other way around?
For HTML, you can use utilities like Tidy or JTidy to turn HTML into well-formed HTML that can be transformed using XSLT. For random text formats, you can try utilities like XFlat at http://www.unidex.com/xflat.htm
.
It is possible to generate database schema in Oracle using a script with CREATE TABLE
, from an XML file generated by a Rational Rose design tool?
All the parser/generator files (such as petal files, XML, and so on) are developed in our project. All the components are designed for reuse, but developed in the context of a lager framework. You have to follow some guidelines, such as modeling in UML, and you must use the base class to get any benefit from our work.
Oracle only generates object types and delivers full object-oriented features such as inheritance in the persistence layer. If you did not need this, the Rational Rose (Petal-File) parser and Oracle packages as the base of the various generators may interest you.
Does Oracle have any tools for creation (based on DTDs or XML Schema Definition DOM) and editing of XML documents with DTD or Schema validation?
JDeveloper9i has an integrated XML Schema-driven code editor for working on XMLSchema-based documents such as XML Schemas and XSLT Stylesheets, with tag-insight to help you easily enter the correct elements and attributes as defined by the schema.
I have been asked to take stored XML docs in v816 and format them as PDF. We are using JDev 3112 as our development environment and the client wants to stick to OAS 4082 on NT if possible. Any suggestions or recommended resources?
Oracle XSQL Pages v1.0.2 supports integration with Apache FOP 0.14.0 for rendering PDF output from XML/SQL input.
It is possible to format XML into PDF using Formatting Object (FOP). See information on this at: http://xml.apache.org/fop/
and http://www.xml.com/pub/rg/75
)
I have a large (27 MB) data-centric XML document. I could not load it into the database when it was split into relational tables with XML SQL Utility, because the DOM parser failed (memory leak) during the XSLT processor execution. Do you have a workaround for this problem? Should I use SAX Parser? How do I use the XSLT processor and Sax Parser?
If this is a one time load, or if the XML document you get always has the same tags, then you might consider using the SQL*Loader (direct path). All you have to do is compose a loader control file (see the Oracle9i Utilities manual, Chapter 3, for examples). You can use the enclosed by
option to describe the fields. For example, in the files list you enter something like the following:
(empno number(10) enclosed by "<empno>" and "</empno>",...)
Except for the data parsing which has to be done the same regardless of what you are using, the actual loading into the database will be fastest with SQL*Loader (as the direct path writes data straight to data blocks, bypassing the layers in between).
If the document is 27 MB because it is a very large number of repeating sub-documents, then you can use the sample code that comes in Chapter 14 of the book "Building Oracle XML Applications" by Steve Muench (O'Reilly) to load XML of any size into any number of tables. In Chapter 14, "Advanced XML Loading Techniques", the example builds an XML Loader utility that does what you are looking for.
Can SQL*Loader handle nesting? That is, what if you have:
... <something> <price>10.00</price> </something> ... ... ... <somethingelse> <price>55.00</price> </somethingelse>
Is there a way to uniquely identify the two <price>
elements?
Not really. The field description in the control file can be nested which is part of the support for object relational columns. The data record to which this maps is of course flat but using all the data-field description features of the SQL*Loader one can get a lot done. For example:
sample.xml
<resultset> <emp> <first>...</first> <last>...</last> <middle>....</middle> <emp> <friend> <first>...</first> <last>...</last> <middle>....</middle> </friend> </resultset>
sample.ctl
-- field definition part of the SQL Loader control file
field list .... ( emp COLUMN OBJECT .... ( first char(30) enclosed by "<first>" and "</first>", last char(30) enclosed by "<last>" and "</last>", middle char(30) enclosed by "<middle>" and </middle>" ) friend COLUMN OBJECT .... ( first char(30) enclosed by "<first>" and "</first>", last char(30) enclosed by "<last>" and "</last>", middle char(30) enclosed by "<middle>" and </middle>" )
Keep in mind that the COLUMN OBJECT
field names have to match the ADT column in the database. Also, you will have to use a custom record terminator, otherwise it defaults to newline
(that is, at every new line it thinks that is has data for a complete database record).
If your XML is more complex and you are trying to extract only select fields, you can use FILLER
fields to reposition the scanning cursor, which scans from where it has left off towards the end of the record (or for the first field, from the beginning of the record).
The SQL*Loader has a very powerful text parser so you can do a lot of neat tricks. For loading XML when the document is very big, but consistent in its tags, you should consider it.
See Also:
Chapter 2, "Modeling and Design Issues for Oracle XML Applications", "Loading XML into a Database" , for guidelines on loading XML |
I am currently investigating SAX. I understand that both the Oracle and IBM parsers use DOM and SAX from W3C.
You will not have to change your code if you stick to SAX interfaces or DOM interfaces for your implementation. That is what the standard interfaces are in place to assist you with.
We are currently architecting some of our future systems to run on XML-based interfaces. We are a large Wall Street institution. Our current systems are all running Oracle 8.0.6, and we would like to have some of our XML concepts implemented on the existing systems due to high demand. Are there current or future plans to support XML-based code within the database, or are there any adapters or cartridges that we can use to get by?
All of our XML Developer's Kit components, including the XML Parser, XSLT Processor, XSQL Servlet, and utilities like the XML SQL Utility all work outside the database against Oracle 8.0.6. However, you will not be able to run XML components inside the database or use Oracle Text (interMedia) XML searching, which are both features in Oracle 8i and higher.
My company has Oracle release 7.3.4 and my group is thinking of using XML for some data transfers between us and our vendors. From what I could see from this Web site, it looks like we would need to move to Oracle8i or higher in order to do so. Is there any way of leveraging Oracle release 7 to do XML?
As long as you have the appropriate JDBC 1.1 drivers for 7.3.4 you should be able to use the XML SQL Utility to extract data in XML.
For JDBC drivers, refer to http://otn.oracle.com/tech/java/sqlj_jdbc/
for information about Oracle7 JDBC OCI and JDBC Thin Drivers.
abcdefg........
' in a particular format? Is it is possible to create a stylesheet that will create these kind of files?
<xsl:output method="text"/>
to output plain text.
Is there a list of browsers that support XML?
The following browsers support the display of XML:
We are considering implementing EDI to communicate requirements with our vendors and customers. I understand that XML is a cheaper alternative for smaller companies. Do you have any information on the advantages of XML over EDI?
Here are some thoughts on the subject:
The next question then becomes: is XML going to replace EDI? Probably not. The technologies will likely coexist, at least for a while. Large companies with an existing investment in EDI will probably use XML as a way to extend their EDI implementation, which raises a new question of XML and EDI integration.
XML is a compelling approach for smaller organizations, and for applications where EDI is inflexible.
What B2B XML standards (such as ebXML, cxml, and BizTalk) does Oracle support? What tools does Oracle offer to create B2B exchanges?
Oracle participates in several B2B standards organizations:
For B2B exchanges, Oracle provides several alternatives depending on customer needs, such as the following:
Oracle Internet Platform provides an integrated and solid platform for B2B exchanges.
What is Oracle Corporation's direction regarding XML?
Oracle Corporation's XML strategy is to use XML in ways that exploit all of the benefits of the current Oracle technology stack. Today you can combine Oracle XML components with the Oracle8i (or higher) database and Advanced Queueing (AQ) to achieve conflict resolution, transaction verification, and so on. Oracle is working to make future releases more seamless for these functions, as well as for functions such as distributed two phase commit transactions.
XML data is stored either object-relational tables or views, or as CLOBs. XML transactions are transactions with one of these datatypes and are handled using the standard Oracle mechanisms, including rollback segments, locking, and logging.
From Oracle, Oracle supports sending XML payloads using AQ. This involves making XML queriable from SQL.
Oracle is active in all XML standards initiatives, including W3C XML Working Groups, Java Extensions for XML, Open Applications Group, and XML.org
for developing and registering specific XML schemas.
Oracle is participating in the W3C Working Group for XML Query. Oracle is considering plans to implement a language that allows querying XML data, such as in the XQL proposal. While XSLT provides static XML transformation features, a query language will add data query flexibility similar to what SQL does for relational data.
Oracle has representatives participating actively in the following 3C Working Groups related to XML/XSL: XML Schema, XML Query, XSL, XLink/XPointer, XML Infoset, DOM, and XML Core.
We have implemented Oracle8i and the XDK. Where can we find basic, standard DTDs to build on for orders, shipments, and acknowledgements?
A good place to start would be this Web site: http://www.xml.org
which is being set up for that purpose.
Is there any support for XML messages enclosing BLOBs, or I should do it on an application level by encoding my binary objects in a suitable text format such as UUENCODE with a MIME wrapper?
XML requires all characters to be interpreted, therefore there is no provision for including raw binary data in an XML document. That being said, you could UUENCODE the data and include it in a CDATA section. The limitation on the encoding technique is to be sure it only produces legal characters for a CDATA section.
If we store XML files as CLOBs in the Oracle database, what is the maximum file size?
The maximum file size is 2 GB. See the Oracle9i Application Developer's Guide - Large Objects (LOBs) for more information on LOBs and CLOBs.
Are there any limitations in the size of an XML file?
There are no XML limitations to an XML file size.
To select data for display and insert data to tables by XML what software do I need? We are using Oracle8i on Solaris.
You need the following software:
The first three can be obtained from Oracle. The fourth can be obtained from Sun Microsystems. If you want to perform the tasks from a browser, you will also need the following:
Is there a whitepaper that discusses the performance of XML and Oracle?
Currently, we do not have any official performance analyses due to the lack of a performance standard or benchmark for XML products.
I have a database with millions of records. I give a query based on some 4/5 parameters, and retrieve the records corresponding to that, I have added indexes in the database for faster retrieval of the same, but since the number of records returned is quite high and I planned to put a previous and next link to show only 10 records at a time, I had to get the count(*)
of the number of records that match.
Since there are so many records, and count(*)
does not consider index, it takes nearly 20-30 seconds for the retrieved list to be seen on the browser window. If I remove that count(*)
, the retrieval is quite fast, but then there is no previous and next as I had linked them to count(*)
.
I presume you are referring on a faster way to retrieve XML documents. The solution is to use SAX interface instead of DOM.
Make sure to select the COUNT(*)
of an indexed column (the more selective the index the better), this way the optimizer can satisfy the count query with a few I/Os of the index blocks instead of a full-table scan.
My application requires communication with outside entities that may have a totally different language system. If I need to put information in other languages (for instance, Chinese) into XML, do I need to treat and process them differently? For example, do I need to care which encoding they use, or would the parser be able to recognize it? Would there be any problems when dealing with the database?
XML inherently supports multiple languages in a single document. Each entity can use a different encoding from the others; that is, you could add a Chinese entity encoded in a Chinese encoding to the rest of the document. You could also treat all portions uniformly, regardless of the language used, by encoding in Unicode. Using the former, you must have an encoding declaration in the XML text declaration.
Oracle XML Parsers are designed to be able to handle most external entities and recognizes a wide range of encodings, including most widely used ones from all over the world.
The database should support all the languages you are going to use on XML. Chinese character sets like ZHS16GBK and ZHT16BIG5 are a superset of ASCII so you may be able to do with one of them to serve for English and Chinese, but you may want to use Unicode to use more languages.
Here is another XML Frequently Asked Question site of interest:
Can you recommend a good XML or XSL book?
http://www.oreilly.com/catalog/orxmlapp/
http://metalab.unc.edu/xml/books/bible/
and it gave me a good understanding of XSLT. Downloading this chapter is free so you can get a good impression.
|
![]() Copyright © 2001, 2003 Oracle Corporation. All Rights Reserved. |
|