DB2 Version 9.7 for Linux, UNIX, and Windows

Multiple XML document decomposition examples

The DECOMPOSE XML DOCUMENTS command uses a single XML schema to decompose a set of XML document stored in a binary or XML column. The data from the XML documents is stored in columns of relational tables based on annotations specified in the schema.

Examples

The following example assumes the relational table ABC.SALESTAB contains two columns SALESDOC and DOCID. The column SALESDOC contains XML documents, and DOCID contains the document identifier for the XML documents are stored in SALESDOC. All the documents correspond to an XML schema registered as ABC.SALES in the XML schema repository (XSR), and the schema has been annotated with decomposition information and enabled for decomposition. Invoke the following DECOMPOSE XML DOCUMENTS command to decompose all the documents stored in ABC.SALESTAB.SALESDOC using the schema ABC.SALES:

DECOMPOSE XML DOCUMENTS IN 'SELECT DOCID, SALESDOC FROM ABC.SALESTAB'
  XMLSCHEMA ABC.SALES 
  MESSAGES /home/myid/errors/errorreport.xml

Alternatively, use the XDB_DECOMP_XML_FROM_QUERY stored procedure to decompose the XML documents. The following stored procedure performs the same decomposition as the previous command.

XDB_DECOMP_XML_FROM_QUERY ('ABC', 'SALES', 'SELECT DOCID, SALESDOC FROM SALESTAB', 
		0, 0, 0, NULL, NULL, 1, numInput, numDecomposed,
		errorreportBuf);

The following command decomposes the customer information in INFO from the CUSTOMER table where the CUSTID is greater than 1003 using the schema CUST_SHRED. The example assumes the schema CUST_SHRED is registered in the XSR.

DECOMPOSE XML DOCUMENTS IN 'SELECT CUSTID, INFO FROM CUSTOMER WHERE CUSTID > 1003'
  XMLSCHEMA CUST_SHRED 
  MESSAGES /home/myid/errors/errorreport.xml