Using the XML Extender, you can insert intact XML documents into an XML column. If you define side tables, the XML Extender automatically updates these tables. When you store an XML document directly, the XML Extender stores the base type as an XML type.
Task overview:
The XML Extender provides two methods for storing XML documents:
default casting functions and storage UDFs. Table 8 shows when to use each method.
Table 8. The XML Extender storage functions
Base type | Store in DB2 as... | ||
---|---|---|---|
XMLVARCHAR | XMLCLOB | XMLFILE | |
VARCHAR | XMLVARCHAR() | N/A | XMLFileFromVarchar() |
CLOB | N/A | XMLCLOB() | XMLFileFromCLOB() |
FILE | XMLVarcharFromFile() | XMLCLOBFromFile() | XMLFILE |
Table 9. The XML Extender default cast functions
Casting used in SELECT clause | Return type | Description |
---|---|---|
XMLVARCHAR(VARCHAR) | XMLVARCHAR | Input from memory buffer of VARCHAR |
XMLCLOB(CLOB) | XMLCLOB | Input from memory buffer of CLOB or a CLOB locator |
XMLFILE(VARCHAR) | XMLFILE | Only store file name |
Example: The following statement inserts a casted VARCHAR type into the XMLVARCHAR type:
INSERT INTO sales_tab VALUES('123456', 'Sriram Srinivasan', db2xml.XMLVarchar(:xml_buff))
Table 10 shows the storage functions provided by the XML
Extender.
Table 10. The XML Extender storage UDFs
Storage user-defined function | Return type | Description |
---|---|---|
XMLVarcharFromFile() | XMLVARCHAR | Reads an XML document from a file on the server and returns the value of the XMLVARCHAR type. |
XMLCLOBFromFile() | XMLCLOB | Reads an XML document from a file on the server and returns the value of the XMLCLOB type. |
XMLFileFromVarchar() | XMLFILE | Reads an XML document from memory as VARCHAR, writes it to an external file, and returns the value of the XMLFILE type, which is the file name. |
XMLFileFromCLOB() | XMLFILE | Reads an XML document from memory as CLOB or a CLOB locator, writes it to an external file, and returns the value of the XMLFILE type, which is the file name. |
Example: The following statement stores a record in an XML table using the XMLCLOBFromFile() function as an XMLCLOB.
EXEC SQL INSERT INTO sales_tab(ID, NAME, ORDER) VALUES( '1234', 'Sriram Srinivasan, XMLCLOBFromFile('c:\dxx\samples\cmd\getstart.xml'))
The preceding example imports the XML object from the file named c:\dxx\samples\cmd\getstart.xml to the column ORDER in the table SALES_TAB.