Start of change

XML input and output overview

The DB2® database server, which manages both relational and XML data, offers various methods for the input and output of XML documents.

XML documents are stored in columns defined with the XML data type. Each row of an XML column stores a single well-formed XML document. The stored document is kept in its XML document form.

XML columns can be defined in tables that contain columns of other types, which hold relational data, and multiple XML columns can be defined for a single table.

Input

The method that you use to put XML data into the database system depends on the task you want to accomplish:

Insert or update
Well-formed documents are inserted into XML columns using the SQL INSERT statement. A document is well-formed when it can be parsed successfully. Validation of the XML documents during an insert or update operation is optional. If validation is performed, the XML schema must first be registered with the XML schema repository (XSR). Documents are updated using the SQL UPDATE statement.
Annotated XML schema decomposition
Data from XML documents can be decomposed or stored into relational and XML columns using annotated XML schema decomposition. Decomposition stores data in columns according to annotations that are added to XML schema documents. These annotations map the data in XML documents to columns of tables.

XML schema documents referenced by the decomposition feature are stored in the XML schema repository (XSR).

XML schema repository (XSR) registration
The XML schema repository (XSR) stores XML schemas that are used for the validation or decomposition of XML documents. Registration of XML schemas is usually a prerequisite for other tasks that are performed on XML documents which have a dependency on these schemas. XML schemas are registered with the XSR using stored procedures provided by DB2.

Output

SQL is used to retrieve the XML data from the database system.

When querying XML data using an SQL fullselect, the query occurs at the column level. For this reason, only entire XML documents can be returned from the query. Start of changeThe XMLTABLE built in table function can be used to retrieve fragments of an XML document in an SQL query.End of change

A number of publishing functions are also available to construct XML values from relational data stored in DB2 database server. XML values constructed with these publishing functions do not have to be well-formed XML documents.

End of change