Mappings from SQL to XML

Db2 maps SQL to XML data according to industry standards and performs several different mappings.

To construct XML data from SQL data, the following mappings are performed:

  • SQL character sets to XML character sets
  • SQL identifiers to XML names
  • SQL data values to XML data values

Db2 maps SQL to XML data according to industry standards. For complete information, see Information technology - Database languages - SQL- Part 14: XML-Related Specifications (SQL/XML) ISO/IEC 9075-14:2003.

Mapping SQL character sets to XML character sets

he character set used for XML data is Unicode UTF-8. SQL character data is converted into Unicode when it is used in XML built-in functions.

Mapping SQL identifiers to XML names

Many SQL identifiers that contain certain characters must be escaped when the SQL identifier is converted into an XML name.

Strings that start with 'XML', in any case combination, are reserved for standardization, and characters such as '#', '{', and '}' are not allowed in XML names. Many SQL identifiers containing these characters need to be escaped when the SQL identifiers are converted into XML names.

Start of changeDb2 applies full escaping to SQL identifiers that are column names when it derives XML names. The mapping converts a colon (:) to _x003A_, _x to _x005F_x, and other restricted characters to a string of the form _xuuuu_ where uuuu is the Unicode value for the character. An identifier with an initial 'XML' (in any case combination) is escaped by mapping the initial x to _x0078_, or the initial X to _x0058_.End of change

Mapping SQL data values to XML data values

SQL data values are mapped to XML values based on SQL data types.

The following data types are not supported and cannot be used as arguments to XML value constructors:

  • ROWID
  • Character strings that are defined with the FOR BIT DATA attribute
  • Binary strings
  • A string or a binary string distinct type that is based on a ROWID, FOR BIT DATA character string, or BLOB

For supported data types, the encoding scheme for XML values is Unicode.