5 The DB2 Data Provider : Returning and Inserting/Updating XML Data in DB2

Returning and Inserting/Updating XML Data in DB2
For DB2 V9.1 and higher for Linux/UNIX/Windows, the DB2 data provider supports the XML data type. By default, the data provider maps the XML data type to the .NET String data type, but you can choose to map the XML data type to the Binary data type by setting the Xml Describe Type connection string option to a value of Binary.
For DB2 V9.5 and higher for Linux/UNIX/Windows, the data provider supports inserting and retrieving XML data in non-Unicode databases.
Returning XML Data
You can specify whether XML data is returned as character or binary data by setting the XML Describe Type connection string option. By default, the data provider maps the XML data type to the .NET String data type. For example, consider a database table defined as:
CREATE TABLE xmlTable (id int, xmlCol xml NOT NULL)
If the application uses the following connection string, the data provider would return XML data as binary data:
"Host=Accounting1;Port=50000;User ID=gene;Password=b0gey;Database=Accnting;
Xml Describe Type=Binary"
Character Data
When the Xml Describe Type is set to String, the result set column is described with a column type of String and the column type name is xml. In this case, your application also can use the following methods to return data stored in XML columns as character data:
GetChars()
GetString()
GetValue()
GetValues()
GetXmlReader()
The data provider converts the XML data returned from the database server from the UTF-8 encoding used by the database server to the UTF-16 .NET String encoding.
Refer to DB2DataReader in the online help for information about the overloaded GetXmlReader method.
Binary Data
When Xml Describe Type is set to Binary, the result set column is described with a column type of BLOB and the column type name is xml. In this case, your application can use the following methods to return XML data as binary data:
GetBytes()
GetValue()
GetValues()
GetXmlReader()
The data provider does not apply any data conversions to the XML data returned from the database server. These methods return a byte array or binary stream that contains the XML data encoded as UTF-8.
If Xml Describe Type is set to String and your application returns data using one of the listed methods, the data provider implicitly converts the character data to binary data.
Inserting/Updating XML Data
The data provider can insert or update XML data as character or binary data, regardless of the setting of the XML Describe Type connection string option.
Character Data
Your application can use the following methods to insert or update XML data as character data:
GetChars()
GetString()
GetValue()
GetValues()
GetXmlReader()
The data provider converts the character representation of the data to the XML character set used by the database server and sends the converted XML data to the server. The data provider does not parse or remove any XML processing instructions.
The data provider interprets the data supplied to these methods using the ISO-8859-1 (latin 1) encoding. The data provider converts the data from ISO-8859-1 to the XML character set used by the database server and sends the converted XML data to the server.
Binary Data
Your application can use the following methods to insert or update XML data as binary data:
GetBytes()
GetValue()
GetValues()
GetXmlReader()
The data provider does not apply any data conversions when sending XML data to the database server.