Chapter 7. Using XML with Java 137
Text LastPgIndValue = document.createTextNode(LastPgIndStr);
// Append text node under element nodes
// Construct the DOM tree
}catch (Exception e) {
System.out.println("Some exception occur: " +
1.Obtain a new instance of a DOM Document object to build a DOM tree
2.Document.createElement() method to create element nodes with specified tagName
3.Document.createTextNode() method to create text nodes with designated values
4.Element.appendChild() method to append text node under element nodes
5.Append element nodes and construct the DOM tree
7.1.4 Binary XML format in Java applications
DB2 10 for z/OS introduces a binary format for XML data to be used with Java applications,
which is called Extensible Dynamic Binary XML DB2 Client/Server Binary XML Format
. This format is an external representation of an XML value that is used only for
exchange with a DB2 client application or the UNLOAD or LOAD utilities. The binary
representation is smaller in size, and it saves the parsing cost.
The IBM Data Server Driver for JDBC and SQLJ can send XML data to the data server or
retrieve XML data from the data server as textual XML data or binary XML data, as shown in
Figure 7-1 on page 138.
138 Extremely pureXML in DB2 10 for z/OS
Figure 7-1 Exchange data as textual or binary XML format
You may set the JCC data source property, xmlFormat, to control whether the data format is
textual XML format or binary XML format. Possible values are as follows:
Specifies that binary XML format is used if the data server supports it. If the data server
does not support binary XML format, textual XML format is used, which is the default.
Specifies that the XML textual format is used.
Specifies that the binary XML format is used.
To change the XML format, set the data source property first, then get a new connection,
which will pick up your setting. Example 7-3 shows the Java code for setting xmlFormat.
Storage and retrieval of binary XML data requires the IBM Data Server Driver for JDBC and
SQLJ version 4.9 or later. If you use the DB2 Client, V9.7 Fix Pack 3a and later provides this
Example 7-3 Setting the xmlFormat
DB2BaseDataSource db2ds=null;
con = ((DB2SimpleDataSource)db2ds).getConnection();
The format of XML data is transparent to the application. The IBM Data Server Driver for
JDBC and SQLJ presents binary XML data to the application only through the XML object
interfaces. The user does not see the data in the binary XML format.
Textual XML
(XML stored format
in the tables)
Binary XML
<root xmlns:foo = “bar”>
<name mgr = “NO”>Bill</name>
<name mgr = “NO”>Joe</name>
Binary XML is smaller in size
Savings in DB2 CPU time during insert and select
Savings in time end to end for insert

Get Extremely pureXML in DB2 10 for z/OS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.