IBM Books

XML Extender Administration and Programming

Decomposing the XML document

The XML Extender provides two stored procedures, dxxShredXML() and dxxInsertXML, to decompose XML documents.

dxxShredXML()
This stored procedure is used for applications that do occasional updates or for applications that do not want the overhead of administering the XML data. The stored procedure dxxShredXML() does not required an enabled collection; it uses a DAD file instead.

The stored procedure dxxShredXML() takes two input parameters, a DAD file and the XML document that is to be decomposed; it returns two output parameters: a return code and a return message.

The stored procedure dxxShredXML() inserts an XML document into an XML collection according to the <Xcollection> specification in the input DAD file. The tables that are used in the <Xcollection> of the DAD file are assumed to exist, and the columns are assumed to meet the data types specified in the DAD mapping. If this is not true, an error message is returned. The stored procedure dxxShredXML() then decomposes the XML document, and it inserts untagged XML data into the tables specified in the DAD file.

The corresponding stored procedure for composition is dxxGenXML(); it also takes the DAD as the input parameter and does not require that the XML collection be enabled.

To decompose an XML collection: dxxShredXML()

Embed a stored procedure call in your application using the following stored procedure declaration:

dxxShredXML(CLOB(100K)    DAD,            /* input */
            CLOB(1M)      xmlobj,         /* input */
            long          returnCode,     /* output */
            varchar(1024) returnMsg)      /* output */

See dxxShredXML() for the full syntax and examples.

Example: The following is an example of a call to dxxShredXML():

#include "dxx.h"
#include "dxxrc.h"
 
EXEC SQL INCLUDE SQLCA;
        EXEC SQL BEGIN DECLARE SECTION;
         SQL TYPE is CLOB      dad;             /* DAD*/
         SQL TYPE is CLOB_FILE dadFile;         /* DAD file*/
         SQL TYPE is CLOB      xmlDoc;          /* input XML document */
         SQL TYPE is CLOB_FILE xmlFile;         /* input XMLfile */
         long                  returnCode;      /* error code */
         char                  returnMsg[1024]; /* error message text */
         short                 dad_ind;
         short                 xmlDoc_ind;
         short                 returnCode_ind;
         short                 returnMsg_ind;
        EXEC SQL END DECLARE SECTION;
 
        /* initialize host variable and indicators */
        strcpy(dadFile.name,"c:\dxx\samples\dad\getstart_xcollection.dad");
        dadFile.name_length=strlen("c:\dxx\samples\dad\getstart_xcollection.dad");
        dadFile.file_option=SQL_FILE_READ;
        strcpy(xmlFile.name,"c:\dxx\samples\cmd\getstart_xcollection.xml");
        xmlFile.name_length=strlen("c:\dxx\samples\cmd\getstart_xcollection.xml");
        xmlFile.file_option=SQL_FILE_READ;
        SQL EXEC VALUES (:dadFile) INTO :dad;
        SQL EXEC VALUES (:xmlFile) INTO :xmlDoc;
        returnCode = 0;
        returnMsg[0] = '\0';
        dad_ind = 0;
        xmlDoc_ind = 0;
        returnCode_ind = -1;
        returnMsg_ind = -1;
 
        /* Call the store procedure */
        EXEC SQL CALL db2xml!dxxShredXML(:dad:dad_ind;
                     :xmlDoc:xmlDoc_ind,
                     :returnCode:returnCode_ind,:returnMsg:returnMsg_ind); 

dxxInsertXML()
This stored procedure is used for applications that make regular updates. Because the same tasks are repeated, improved performance is important. Enabling an XML collection and using the collection name in the stored procedure improves performance. The stored procedure dxxInsertXML() works the same as dxxShredXML(), except that dxxInsertXML() takes an enabled XML collection as its first input parameter.

The stored procedure dxxInsertXML() inserts an XML document into an enabled XML collection, which is associated with a DAD file. The DAD file contains specifications for the collection tables and the mapping. The collection tables are checked or created according to the specifications in the <Xcollection>. The stored procedure dxxInsertXML() then decomposes the XML document according to the mapping, and it inserts untagged XML data into the tables of the named XML collection.

The corresponding stored procedure for composition is dxxRetrieveXML(); it also takes the name of an enabled XML collection.

To decompose an XML collection: dxxInsertXML()

Embed a stored procedure call in your application using the following stored procedure declaration:

dxxInsertXML(char(UDB_SIZE) collectionName,   /* input */
             CLOB(1M)       xmlobj,           /* input */
             long           returnCode,       /* output */
             varchar(1024)  returnMsg)        /* output */

See dxxInsertXML() for the full syntax and examples.

Example: The following is an example of a call to dxxInsertXML():

#include "dxx.h"
#include "dxxrc.h"
 
EXEC SQL INCLUDE SQLCA;
        EXEC SQL BEGIN DECLARE SECTION;
         char                  collection[64];   /* name of an XML collection */
         SQL TYPE is CLOB_FILE xmlFile;          /* input XML file */
         SQL TYPE is CLOB      xmlDoc;           /* input XML doc */
         long                  returnCode;       /* error code */
         char                  returnMsg[1024];  /* error message text */
         short                 collection_ind;
         short                 xmlDoc_ind;
         short                 returnCode_ind;
         short                 returnMsg_ind;
         EXEC SQL END DECLARE SECTION;
         
         /* initialize host variable and indicators */
         strcpy(collection,"sales_ord")
         strcpy(xmlobj.name,"c:\dxx\samples\cmd\getstart_xcollection.xml");
         xmlobj.name_length=strlen("c:\dxx\samples\cmd\getstart_xcollection.xml");
         xmlobj.file_option=SQL_FILE_READ;
         SQL EXEC VALUES (:xmlFile) INTO (:xmlDoc);
         returnCode = 0;
         returnMsg[0] = '\0';
         collection_ind = 0;
         xmlobj_ind = 0;
         returnCode_ind = -1;
         returnMsg_ind = -1;
 
         /* Call the store procedure */
         EXEC SQL CALL db2xml!dxxInsertXML(:collection:collection_ind;
                      :xmlDoc:xmlDoc_ind,
                      :returnCode:returnCode_ind,:returnMsg:returnMsg_ind); 


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]