Chapter 7. Using XML with Java 137
Text LastPgIndValue = document.createTextNode(LastPgIndStr);
//************************************************************************
// Append text node under element nodes
//************************************************************************
MsgId.appendChild(MsgIdValue);
4
CreDtTm.appendChild(CreDtTmValue);
PgNb.appendChild(PgNbValue);
LastPgInd.appendChild(LastPgIndValue);
//************************************************************************
// Construct the DOM tree
//************************************************************************
MsgPgntn.appendChild(PgNb);
5
MsgPgntn.appendChild(LastPgInd);
GrpHdr.appendChild(MsgId);
GrpHdr.appendChild(CreDtTm);
GrpHdr.appendChild(MsgPgntn);
document.appendChild(GrpHdr);
}catch (Exception e) {
System.out.println("Some exception occur: " +
e.getMessage());
}
Note:
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
(XDBX)
1
. 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.
1
http://www.ibm.com/support/docview.wss?uid=swg27019354&aid=1
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:
com.ibm.db2.jcc.DB2BaseDataSource.XML_FORMAT_NOT_SET
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.
com.ibm.db2.jcc.DB2BaseDataSource.XML_FORMAT_TEXTUAL
Specifies that the XML textual format is used.
com.ibm.db2.jcc.DB2BaseDataSource.XML_FORMAT_BINARY
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
support.
Example 7-3 Setting the xmlFormat
DB2BaseDataSource db2ds=null;
...
db2ds.setXmlFormat(com.ibm.db2.jcc.DB2BaseDataSource.XML_FORMAT_BINARY);
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
DB2
(XML stored format
in the tables)
Binary XML
<root xmlns:foo = “bar”>
<Person>
<name mgr = “NO”>Bill</name>
<foo:age>35</foo:age>
</Person>
<Person>
<name mgr = “NO”>Joe</name>
<foo:age>45</foo:age>
</Person>
</root>
I3foo1I3bar2m12
X4root300
X6Person400X4name500Y3mgr6002NOT4BillzX3age712T235zz
e4e5a62NOT3Joezx712T245zz
zZ
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.