XML data type

The XML data type is used to define columns of a table that store XML values. This data type provides the ability to store well-formed XML documents in a database.

All XML data is stored in the database in an internal representation. Character data in this internal representation is in the UTF-8 encoding scheme. The internal representation of values in an XML column is not a string and not directly comparable to string values.

An XML value can be transformed into a textual XML value that represents the XML document in the following ways:

  • By using the XMLSERIALIZE function
  • By retrieving the value into an application variable of an XML, string, or binary type

Similarly, a textual XML value that represents an XML document can be transformed to an XML value by using the XMLPARSE function or by storing a value from a string, binary, or XML application data type in an XML column.

A binary XML value is a value that is in the Extensible Dynamic Binary XML DB2® Client/Server Binary XML Format. This format is an external representation of an XML value that is only used for exchange with a DB2 client application or the UNLOAD or LOAD utilities. The binary representation provides more efficient XML parsing. An XML value can be transformed into a binary XML value that represents the XML document in the following ways:

  • In a JDBC or SQLJ application, by retrieving the XML column value into an java.sql.SQLXML object, and then retrieving the data from the java.sql.SQLXML object as a binary data type, such as InputStream. JDBC 4.0 or later provides support for the java.sql.SQLXML data type.
  • In an ODBC application, by binding the XML column to an application variable with the SQL_C_BINARYXML data type, and retrieving the XML value into that application variable.
  • By running the UNLOAD utility, and using one of the following field specifications for the XML output:
    CHAR BLOBF template-name BINARYXML
    VARCHAR BLOBF template-name BINARYXML
    XML BINARYXML

Similarly, a binary value that represents an XML document can be transformed to an XML value in the following ways:

  • In a JDBC or SQLJ application, by assigning the input value to an java.sql.SQLXML object, and then inserting the data from the java.sql.SQLXML object into the XML column.
  • In an ODBC application, by binding a parameter marker for input to an XML column to an application variable with the SQL_C_BINARYXML data type, and inserting the binary data into the XML column.
  • By running the LOAD utility, and using one of the following field specifications for the XML input:
    CHAR BLOBF BINARYXML
    VARCHAR BLOBF BINARYXML
    XML BINARYXML

The size of an XML value in a DB2 table has no architectural limit. However, textual XML data that is stored in or retrieved from an XML column is limited to 2 GB.

Start of changeValidation of an XML document against an XML schema is supported. XML schema validation is typically performed during INSERT or UPDATE into an XML column. If an XML column has an XML type modifier, only documents that are valid according to the XML schema that is specified by the XML type modifier can be inserted into the column. If an XML column does not have an XML type modifier, validation is optional.End of change