Usage

XML documents can define their own markup language. The grammar for the markup language is defined using a DTD file. Three object types can be included in an XML document: elements, attributes, and text. XML Extender provides a DTD for a special XML document called a Data Access Definition (DAD) file. DAD files are used to define how XML documents are mapped to and from a DB2 database. This is called node mapping.

DAD files can use two types of node mapping: SQL node mapping and Remote Database (RDB) node mapping. SQL node mapping provides mapping instructions in the form of an SQL statement. Special XML Extender rules in the format of the SQL statement must be followed. Refer to the XML Extender Administration Guide for details. SQL node mapping can only be used to compose or create new XML documents from existing data stored in DB2 tables. It cannot break down or decompose an XML document into elements and insert them into database tables.

RDB node mapping supports both composition and decomposition of XML documents. RDB node mapping uses the Extensible Path standard (XPath) to identify elements, attributes, and text contained inside an XML document. Each element, attribute, and text object is assigned to a column in a database table. XPath is also used to search XML documents that are not decomposed using XML Columns.

XML Columns

XML Columns are used to store XML documents inside a DB2 column without decomposition. UDFs are provided to perform common tasks. XML Columns support document validation, storage, retrieval, updates, and extracts. Documents are validated using a DTD file. Documents can be stored and retrieved in full or by specified elements and attributes using the XPath standard. Fast searches are available using side tables. Side tables duplicate frequently accessed elements and attributes into DB2 tables indexed with a primary key using RDB node mapping. The XML column must be defined with one of the following data types depending on the size of the documents:

  • XMLVarchar— Stores small XML documents with base type VARCHAR(3000).

  • XMLCLOB— Stores large XML documents with base type CLOB(2G).

  • XMLFile— References an external XML document file name using base type VARCHAR(512).

UDFs are available for storing, retrieving, updating, and extracting data from XML documents stored in an XML Column. Table 18.1 lists these UDFs.

Table 18.1. XML Column UDFs
FunctionDescription
XMLVarcharFromFileImports an XML document from a file to an XMLVarchar
XMLCLOBFromFileImports an XML document from a File to an XMLCLOB
XMLFileFromVarcharImports an XML document from a CLOB format to an XMLFile
XMLFileFromCLOBImports an XML document from a CLOB format into an XMLFile
ContentExports an XML document from an XMLVarchar, XMLCLOB, or an XMLFile
UpdateReplaces XML document stored in an XML Column by only changing some element or attribute value
extractIntegerFinds an element or attribute within an XML document which only has a single value
extractIntegersFinds an element or attribute within an XML document which has multiple occurred values

In general, XML Columns are slower to update and extract values from an XML document than XML Collections. When an update on a single element or attribute is needed on an XML document stored in an XML Column, the entire document is replaced, which is not very efficient. Side tables improve the performance of selecting or extracting elements and attributes, but add extra overhead when inserting or importing XML documents. This is due to the extra cost of maintaining the indexed data stored in a separate table. If performance is a necessity, XML Collections may be more suitable.

XML Collections

XML Collections are used for composing and decomposing XML documents to and from relational databases. Composition is useful when existing data stored in a relational database needs to be translated into XML format. Decomposition is useful for improving UPDATE performance of frequently modified XML documents in which only small parts of the document are updated.

To enable an XML Collection, you must provide a DAD file to define the mapping. XML Collections support both SQL node mapping and RDB node mapping. XML Collections use DB2 stored procedures for generating, retrieving, shredding, and inserting XML documents. Table 18.2 lists these stored procedures.

Table 18.2. XML Collection Stored Procedures
FunctionDescription
db2xml.dxxGenXMLGenerates XML documents dynamically by passing a DAD
db2xml.dxxRetrieveXMLComposes XML documents from an enabled XML Collection
db2xml.dxxShredXMLDecomposes XML documents dynamically by passing a DAD
db2xml.dxxInsertXMLDecomposes XML Documents into an enabled XML Collection

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.248.1