|Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)
Part Number A86030-01
Introduction to Oracle XML, 13 of 27
Data may be in the form of structured documents, where the structure is known a priori and is the same for all instances. In this case, the document can be stored in relational or object-relational structures. In this case as well, the object-relational type system can provide a direct mapping to the XML document.
This mapping is relatively straight forward and Oracle XML-SQL Utility (XSU) offers an insert mechanism that can map an XML document directly into a given table or view.
To reiterate, XML-SQL Utility stores XML data by preserving XML structure as follows:
The example XML document given earlier can be inserted into the database using the XML-SQL Utility as follows:
String xmlDoc = " ...the actual xml document... "; Connection conn = DriverManager.getConnection(...); OracleXMLSave sav = new OracleXMLSave(conn,"purchaseOrderTab"); sav.insertXML(xmlDoc);
The advantage of storing an XML document as an object-relational instance is that the structure of the document is preserved in the database as well. This allows the XML document to be viewed and traversed in SQL in a way similar to a XPath traversal on the document.
For instance a XPath traversal such as,
can be easily represented as an attribute traversal in SQL:
Mapping to Object-Relational storage enables existing database applications to work against XML data. Also, functionality provided by Oracle8i on Object-Relational columns, such as indexing, partitioning, and parallel query, can be leveraged.
However, using such a mapping, the original document is not exactly reproducible. For instance, comments are lost. But this can be avoided by storing a copy of the original document in a CLOB as discussed in the following section, and using the object-relational mapped data for query efficiency purposes.
Another potential problem could arise due to the ordering amongst the elements. In order to preserve the element ordering, you can have a special column in the underlying table and order the results using that column.