Programming XML Toolkit
Programming XML Toolkit
7.2
Programming
Programming XML Toolkit
IBM
Note
Before using this information and the product it supports, read the information in “Notices” on page
15.
This edition applies to IBM® i 7.2 (product number 5770-SS1) and to all subsequent releases and modifications until
otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor
does it run on CISC models.
This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is
licensed to you under the terms of the IBM License Agreement for Machine Code.
© Copyright International Business Machines Corporation 1999, 2013.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
Contents
XML Toolkit........................................................................................................... 1
PDF file for XML Toolkit................................................................................................................................ 1
XML introduction.......................................................................................................................................... 2
Advantages of XML................................................................................................................................. 2
Uses of XML............................................................................................................................................ 3
XML standards and extensions.............................................................................................................. 4
XML Toolkit introduction.............................................................................................................................. 5
Available XML Toolkit components........................................................................................................ 6
Installing XML Toolkit............................................................................................................................. 7
API documentation.................................................................................................................................9
Samples................................................................................................................................................ 10
XSL introduction.........................................................................................................................................11
Uses of XSL........................................................................................................................................... 11
XML Scripting for IBM i introduction......................................................................................................... 12
Getting support.......................................................................................................................................... 12
Related information for XML Toolkit..........................................................................................................12
Notices................................................................................................................15
Programming interface information.......................................................................................................... 16
Trademarks................................................................................................................................................ 16
iii
iv
XML Toolkit
The IBM XML Toolkit for IBM i, licensed program offering (LPO) 5733-XT2, V1R2M0, is designed to
provide key development enablement components, XML parsers, to assist in the use of XML for general
application or business-to-business (B2B) solutions. The XSL transformer allows you to reformat or
reorganize XML documents to other formats (for example, XML or HTML).
The XML Toolkit for IBM i is based on cross-platform, open-source code that is designed to be compliant
with industry standards. Parser version 5.6.3 corresponds to Apache Software Foundations' Xerces-C
Version 2.6 with fixes. The XSL transformer corresponds to Apache Software Foundations' Xalan-C
Version 1.10.2. In addition to providing the XML for C++ parser and the XSL transformer for C++, a unique
interface called XML Procedural parser is provided to the XML for C++ parser that allows applications
written in RPG, C, or COBOL to access an XML parser.
Also included with the XML Toolkit is XML Scripting for IBM i. XML Scripting for IBM i provides an XML
based build tool.
Other information
• IBM Redbooks® publications:
– The Ins and Outs of XML and Db2® for i (about 3 MB)
– The XML Files: Using XML for Business-to-Business and Business-to-Consumer Applications (about 3
MB)
– Integrating XML with DB2® XML Extender and DB2 Text Extender (about 4.5 MB)
Advantages of XML
Using XML to exchange information offers many benefits.
Advantages of XML include the following:
• XML uses human, not computer, language. XML is readable and understandable, even by novices, and
no more difficult to code than HTML.
• XML is completely compatible with Java™ and 100% portable. Any application that can process XML can
use your information, regardless of platform.
• XML is extendable. Create your own tags, or use tags created by others, that use the natural language of
your domain, that have the attributes you need, and that makes sense to you and your users.
The following example illustrates, in a simplified way, the readability and extensibility of XML:
<HTML>
<H1 ID="MN">State</H1> <?XML VERSION="1.0" STANDALONE="yes" ?>
<H2 ID="12">City</H2> <STATE STATEID="MN">
<DL> <CITY CITYID="12">
<DT>Name</DT> <NAME>Johnson</name>
<DD>Johnson</DD> <POPULATION>5000</POPULATION>
<DT>Population</DT> </CITY>
<DD>5000</DD> <CITY CITYID="15">
</DL> <NAME>Pineville</NAME>
<H2 ID="15">City</H2> <POPULATION>60000</POPULATION>
<DL> </CITY>
<DT>Name</DT> <CITY CITYID="20">
<DD>Pineville</DD> <NAME>Lake Bell</NAME>
<DT>Population</DT> <POPULATION>20</POPULATION>
<DD>60000</DD> </CITY>
</DL> </STATE>
<H2 ID="20">City</H2>
<DL>
<DT>Name</DT>
<DD>Lake Bell</DD>
<DT>Population</DT>
<DD>20</DD>
</DL>
</HTML>
HTML tag names reveal nothing about the meaning of their content. The example above uses an HTML
definition list, but the problems inherent in using HTML occur if the data were contained in a table or
some other kind of HTML tags. Examples follow:
• Many of the HTML tags are acronyms, so they are not as readable as common language.
• HTML tags represent data (in this example, city names and populations) as items to display, for
example, as definitions in a list or cells in a table. This makes it difficult to manipulate the data or
to exchange it between applications.
The XML tag names are readable and convey the meaning of the data. The information structure is easily
discerned by both humans and computers as each XML tag immediately precedes the associated data.
The data structure follows a noticeable and useful pattern, making it easy to manipulate and exchange the
data.
Uses of XML
XML has a variety of uses for Web, e-business, and portable applications.
The following are some of the many applications for which XML is useful:
• Web publishing: XML allows you to create interactive pages, allows the customer to customize those
pages, and makes creating e-commerce applications more intuitive. With XML, you store the data once
and then render that content for different viewers or devices based on style sheet processing using an
Extensible Style Language (XSL)/XSL Transformation (XSLT) processor.
• Web searching and automating Web tasks: XML defines the type of information contained in a
document, making it easier to return useful results when searching the Web:
For example, using HTML to search for books authored by Tom Brown is likely to return instances of the
term 'brown' outside of the context of author. Using XML restricts the search to the correct context (for
example, the information contained in the <author> tag) and returns only the information that you want.
By using XML, Web agents and robots (programs that automate Web searches or other tasks) are more
efficient and produce more useful results.
• General applications: XML provides a standard method to access information, making it easier for
applications and devices of all kinds to use, store, transmit, and display data.
• e-business applications: XML implementations make electronic data interchange (EDI) more
accessible for information interchange, business-to-business transactions, and business-to-consumer
transactions.
XML Toolkit 3
• Metadata applications: XML makes it easier to express metadata in a portable, reusable format.
• Pervasive computing: XML provides portable and structured information types for display on pervasive
(wireless) computing devices such as personal digital assistants (PDAs), cellular phones, and others.
For example, WML (Wireless Markup Language) and VoiceXML are currently evolving standards for
describing visual and speech-driven wireless device interfaces.
APIs
Application programming interfaces (APIs) allow applications to work with XML information using a
standard set of portable interfaces.
DOM 1.0 and DOM Level 2.0
The Document Object Model (DOM) API enables you to build XML documents as well as parse them.
These interfaces enable you to access, manipulate, and create XML documents (and the data within) as
programming objects that have methods and events. Your programs can construct or change a DOM tree
in memory and then persist that DOM tree to a file or stream. DOM is best suited for instances where you
will parse few XML documents but require extensive control over the contents.
Namespaces
Namespaces are pointers that enable you to differentiate between duplicate XML elements or attribute
names, a situation that can occur when using XSLT style sheets or more than a single DTD. For example,
the <code> element from one DTD might mean something different from a <code> element in another
DTD. To avoid name collisions and ambiguity, give each pointer a unique local name. This makes it simple
to distinguish between the different namespaces.
SAX 1.0 and SAX 2.0
The Simple API for XML (SAX) is a read-only, single-pass interface best suited for processing many
documents or very large documents. You can use this API to extract information from the XML
documents, but you cannot use it to add new data to or to change the content of the XML documents.
XLink
XML Linking Language (XLink) enables you to link your XML document to other resources on the web,
including files of just about any format, database searches, and so on. Moreover, you can link to the
structure of the resource, not a predetermined place holder, like an HTML <A NAME> anchor tag. Multiple
links allow users to traverse the linked information in any order according to restrictions that you specify.
XML Schema
XML Schema Language defines the logical structure of an XML document, much like a document type
definition (DTD).
The significant difference between DTDs and XML Schemas are that schemas do the following:
• Are written as XML markup language itself, making them extensible, unlike DTDs
• Focus on the problem of cardinality, enabling the enumeration of minimum and maximum allowed
elements
• Allow constraints on values
• Allow additional data types and definitions of data types that can be inherited
All of these enhancements give you more control over the allowable content of the XML document or
message. For example, you can add a different type of element to an existing schema as long as your
addition does not break the original schema. Schemas also have many more available data types than do
DTDs, making importing and exporting data somewhat easier.
XML Toolkit 5
both the C++ and the procedural languages and the XSL transformer consists of two installation options in
the 5733-XT2 product.
The first installation option provides the service programs that support that parser version and the XSL
transformer. The second installation option provides include files, samples, API documentation, and
bind instruction associated with the parser version and transformer. XML Scripting for IBM i contains a
program, service program, samples, and documentation.
Related information
XML for i5/OS home page
XML Toolkit 7
XML Toolkit V1R2M0 Options Contents
XML version 5.6.3 parser service programs.
This option is installed as QXML4C563 and
QXML4PR563 in library QXMLLIBV4.
Option 4
In addition, XSL version 1.10 transformer
service program is installed as service program
QXSL4C112 in library QXMLLIBV4.
All samples and documentation are distinguished by the XML parser, XSL transformer, and XML Scripting
version. For XML, this is library QXMLDEVnnn and integrated file system directory /QIBM/ProdData/
xmltoolkit2/XMLn_n_n, where nnn and n_n_n refer to the XML version.
For XSL, this is library QXSLDEVnnn and integrated file system directory /QIBM/ProdData/xmltoolkit2/
XSLn_n_n, where nnn and n_n_n refer to the XSL version.
For XML Scripting, this is integrated file system directory /QIBM/ProdData/xmltoolkit2/scriptingn_n,
where nnn and n_n refer to the XML Scripting version.
API documentation
The documentation for each XML parser version is available in browser format when you install the
appropriate licensed program development option for the XML parser version of your choice.
To view the documentation, map a network drive to your target system and, using your browser, open the
file location specified in the table below.
The documentation includes API descriptions, information about how to create and run the sample
programs, some programming information, and frequently asked questions (FAQ).
XML Toolkit 9
For information about mapping network drives, see Accessing file shares from a Windows client.
Related concepts
Accessing file shares from a Windows client
Samples
Samples for each XML parser, XSL transformer, and XML Scripting version provided with the XML Toolkit
are available by installing the appropriate development option for each.
Samples
Samples for each XML parser, XSL transformer, and XML Scripting version provided with the XML Toolkit
are available by installing the appropriate development option for each.
For XML, C++ samples are provided through integrated file system files. RPG, C, and COBOL samples are
provided through source physical files.
For XSL, the C and C++ samples are provided through integrated file system files.
For XML Scripting, the samples are provided through integrated file system files.
The version for these is indicated in either the integrated file system path location (n_n_n or n_n) or in
the name of the tools development library (QXMLDEVnnn for XML or QXSLDEVnnn for XSL). Information
describing the function of each sample and how to create, bind, and run the samples for a given
supported language are provided. See the “API documentation” on page 9.
A source file, QCLSRC, is provided in the tools development library and contains members that create the
samples provided for each language version.
Related concepts
API documentation
The documentation for each XML parser version is available in browser format when you install the
appropriate licensed program development option for the XML parser version of your choice.
XSL introduction
Extensible Stylesheet Language (XSL) allows you to format and reorganize existing XML documents into
another format (for example, XML or HTML).
You can use XSL to reformat an XML file to specify the how the data is to be presented on the web via
XSLT stylesheets. You can also write XSLT stylesheets to reorganize an XML document to remove or add
elements or to change it into another XML document. XSLT stylesheets are written in XML to achieve this.
This process has two basic components:
• Use XSL stylesheets to define a set of patterns and templates you want to use to replace XML elements.
A pattern identifies the XML element, and the corresponding template is used by an XSL processor to
actually replace the XML element. For example, you can transform data elements in an XML document
to display appropriately in a browser or mailing label.
• Use XSLT documents to transform the hierarchy of XML data into a different kind of tree, reordering
elements as you prefer. For example, you can add a table of contents or an index to a set of data
that does not have one. You can also use XSLT to transform the grammar of XML documents. For
example, you can transform the grammar for a set of incoming XML request documents to a different
XML grammar required by the receiving application.
These technologies do more than format the display of an XML document. They change it so that it
becomes a different kind of document. In conjunction with other XML tools and extensions, such as
parsers and XML Linking Language (XLink), you can produce new documents formats such as specific
word processing formats, portable document format (PDF), HTML, and more.
Uses of XSL
XSL can be used for many XML transformation and reformatting tasks.
The transformation and reformatting tasks that you can do with XSL include the following:
• XML to HTML rendering
• XML vocabulary conversion
• XML to plain text conversion
• Simple XML queries
XML Toolkit 11
XML Scripting for IBM i introduction
XML Scripting for IBM i uses an XML formatted file to accomplish a set of tasks on the system. These tasks
are grouped in "targets" which allow a different set of tasks to be run in different invocations of the XML
Scripting tool. The targets can have dependencies on each other.
The XML Scripting for IBM i tool is inspired by Apache Ant, but it is not compatible with that product and
has a different focus. Currently, the tool is available only in the English language and has no extension
API.
Getting support
Review the statement of support for the XML Toolkit.
Support services for the XML Toolkit are provided under the typical terms and conditions for IBM software
products. Support services include program services, voice support, and consulting services. Use the
online information provided at the System i5® Home Page under the topic Support for more information,
or contact your local IBM representative. These terms and conditions include the following:
• You may, at IBM direction, be required to obtain a more current level of the XML Toolkit and move to
a newer version of the XML parser, XSL transformer, or XML Scripting to receive Continued Program
Services (CPS) support.
• Resolving defects with the XML Toolkit parsers are supported under program services or voice support.
Resolving application programming or debugging problems is supported under consulting services.
• XML Toolkit application programming interface (API) calls are supported under consulting services
unless:
– It is clearly an XML Toolkit API defect as demonstrated by recreation in a relatively simple program.
– It is a question that asks for documentation clarifications.
– It is a question about the location of samples or documentation.
• All programming assistance is supported under consulting services. This includes the program samples
that are provided in the XML Toolkit licensed program.
• If you believe that there is a potential defect in the XML Toolkit APIs, a simple program that
demonstrates the error is required.
Related concepts
System i5 Home Page
• The Ins and Outs of XML and Db2 for i (about 3 MB)
• The XML Files: Using XML for Business-to-Business and Business-to-Consumer Applications (about 3
MB)
• Integrating XML with DB2 XML Extender and DB2 Text Extender (about 4.5 MB)
Other information
• developerWorks® XML Zone
• XML on System i®
XML Toolkit 13
14 IBM i: Programming XML Toolkit
Notices
This information was developed for products and services offered in the U.S.A.
IBM may not offer the products, services, or features discussed in this document in other countries.
Consult your local IBM representative for information on the products and services currently available in
your area. Any reference to an IBM product, program, or service is not intended to state or imply that
only that IBM product, program, or service may be used. Any functionally equivalent product, program, or
service that does not infringe any IBM intellectual property right may be used instead. However, it is the
user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service.
IBM may have patents or pending patent applications covering subject matter described in this
document. The furnishing of this document does not grant you any license to these patents. You can
send license inquiries, in writing, to:
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of
express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
IBM Corporation
Software Interoperability Coordinator, Department YBWA
3605 Highway 52 N
Rochester, MN 55901
U.S.A.
If you are viewing this information softcopy, the photographs and color illustrations may not appear.
Trademarks
IBM, the IBM logo, and ibm.com® are trademarks or registered trademarks of International Business
Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be
16 Notices
trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at
"Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or
trademarks of Adobe Systems Incorporated in the United States, and/or other countries.
IT Infrastructure Library is a registered trademark of the Central Computer and Telecommunications
Agency which is now part of the Office of Government Commerce.
Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon,
Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or
its subsidiaries in the United States and other countries.
Linux® is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the
United States, other countries, or both.
ITIL is a registered trademark, and a registered community trademark of the Office of Government
Commerce, and is registered in the U.S. Patent and Trademark Office.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Cell Broadband Engine is a trademark of Sony Computer Entertainment, Inc. in the United States, other
countries, or both and is used under license therefrom.
Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in the United
States, other countries, or both.
Other product and service names might be trademarks of IBM or other companies.
Notices 17
18 IBM i: Programming XML Toolkit
IBM®