Encoding scenarios for retrieval of XML data with implicit serialization

The target encoding and application code page can affect data conversion, truncation due to expansion, and internal encoding during XML data retrieval with implicit serialization.

The following examples demonstrate these interactions.

Only scenario 1 and scenario 2 apply to Java™ applications, because the application code page for Java applications is always Unicode. In general, code page conversion is not a problem for Java applications.

Scenario 1

Encoding source Value
Target data encoding UTF-8 Unicode
Target application data type Binary
Application code page Not applicable
Example output statements:
SELECT XMLCOL FROM T1

Character conversion: None.

Data loss: None.

Truncation due to expansion: None.

Internal encoding in the textual XML data: For applications other than Java applications, the data is prefixed by the following XML declaration:
<?xml version="1.0" encoding="UTF-8" ?>
For Java applications, no encoding declaration is added, unless you cast the data as the com.ibm.db2.jcc.DB2Xml type, and use a getDB2Xmlxxx method to retrieve the data. The declaration that is added depends on the getDB2Xmlxxx that you use.

Scenario 2

Encoding source Value
Target data encoding UTF-16 Unicode
Target application data type Graphic
Application code page CCSID 1208
Example output statements:
SELECT XMLCOL FROM T1

Character conversion: Data is converted from UTF-8 to UTF-16.

Data loss: None.

Truncation due to expansion: Truncation can occur during conversion from UTF-8 to UTF-16, due to expansion.

Internal encoding in the textual XML data: For applications other than Java applications, the data is prefixed by a UTF-16 Byte Order Mark (BOM) and the following XML declaration:
<?xml version="1.0" encoding="UTF-16" ?>
For Java applications, no encoding declaration is added, unless you cast the data as the com.ibm.db2.jcc.DB2Xml type, and use a getDB2Xmlxxx method to retrieve the data. The declaration that is added depends on the getDB2Xmlxxx that you use.

Scenario 3

Encoding source Value
Target data encoding ISO-8859-1 data
Target application data type Character
Application code page 819
Example output statements:
SELECT XMLCOL FROM T1

Character conversion: Data is converted from UTF-8 to CCSID 819.

Data loss: Possible data loss. Some UTF-8 characters cannot be represented in CCSID 819. The Db2 database system generates an error.

Truncation due to expansion: None.

Internal encoding in the textual XML data: The data is prefixed by the following XML declaration:
<?xml version="1.0" encoding="ISO-8859-1" ?>

Scenario 4

Encoding source Value
Target data encoding Windows-31J data (superset of Shift_JIS)
Target application data type Graphic
Application code page 943
Example output statements:
SELECT XMLCOL FROM T1

Character conversion: Data is converted from UTF-8 to CCSID 943.

Data loss: Possible data loss. Some UTF-8 characters cannot be represented in CCSID 943. The Db2 database system generates an error.

Truncation due to expansion: Truncation can occur during conversion from UTF-8 to CCSID 943 due to expansion.

Internal encoding in the textual XML data: The data is prefixed by the following XML declaration:
<?xml version="1.0" encoding="Windows-31J" ?>