Home > Articles > Web Services > XML

pureXML: Using XML in DB2 for z/OS

This chapter introduces you to the basics of XML and provides an overview of pureXML, IBM’s implementation of XML support embedded in DB2.
This chapter is from the book

XML is gaining popularity for persisting complex data and is frequently used in web-enabled applications and as a means of data transmission. This chapter introduces you to the basics of XML and provides an overview of pureXML, IBM’s implementation of XML support embedded in DB2.

A comprehensive treatment of DB2 pureXML would require a book length treatment, and it is not the intent of this book, or this chapter, to provide an exhaustive treatment of DB2’s support for XML. If you are looking for an introduction, this chapter is a good starting place. References for additional pureXML research are provided at the end of the chapter.

What Is XML?

XML stands for Extensible Markup Language. You may be familiar with HTML, the markup language used to create web pages. Like HTML, XML is based upon Standard Generalized Markup Language (SGML). SGML is a language for defining markup languages that was developed and standardized by the International Organization for Standardization (ISO).

Whereas HTML uses tags to describe how data appears on a web page, XML is designed to transport and store data. In other words, XML uses tags to describe the what—that is, the data itself. XML retains the key SGML advantage of self-description, while avoiding the complexity of full-blown SGML. XML allows tags to be defined by users that describe the data stored in the document. This capability gives users a means for describing the structure and nature of the data in the document. In essence, the document becomes self-describing.

The simple syntax of XML makes it easy to process by machine while remaining understandable to people. Again, use HTML as a metaphor to help you understand XML. HTML uses tags to describe the appearance of data on a page. For example the tag, “text”, would specify that the “text” data should appear in bold face. XML uses tags to describe the data itself, instead of its appearance. For example, consider the following XML describing a customer address:

<CUSTOMER>
   <first_name>Craig</first_name>
   <middle_initial>S.</middle_initial>
   <last_name>Mullins</last_name>
   <company_name>Mullins Consulting, Inc.</company_name>
   <street_address>15 Coventry Ct.</street_address>
   <city>Sugar Land</city>
   <state>TX</state>
   <zip_code>77479</zip_code>
   <country>USA</country>
</CUSTOMER>

XML is actually a meta-language—that is, a language for defining other markup languages. These languages are collected in dictionaries called Document Type Definitions (DTDs). The DTD stores definitions of tags for specific industries or fields of knowledge. So, the meaning of a tag must be defined in a “document type declaration” (DTD), such as the following:

<!DOCTYPE CUSTOMER [
  <!ELEMENT CUSTOMER (first_name, middle_initial, last_name,
             street_address, city, state, zip_code, country)>
  <!ELEMENT first_name (#PCDATA)>
  <!ELEMENT middle_initial (#PCDATA)>
  <!ELEMENT last_name (#PCDATA)>
  <!ELEMENT street_address (#PCDATA)>
  <!ELEMENT city (#PCDATA)>
  <!ELEMENT state (#PCDATA)>
  <!ELEMENT zip_code (#PCDATA)>
  <!ELEMENT country (#PCDATA)>
]

The DTD for an XML document can either be part of the document or stored in an external file. The XML code samples shown are meant to be examples only. By examining them, you can quickly see how the document describes its contents.

For data management professionals, this is a plus because it eliminates the trouble to track down the meaning of data elements. One of the biggest problems associated with database management and processing is finding and maintaining the meaning of stored data. If the data can be stored in documents using XML, the documents themselves will describe their data content. Of course, the DTD is a rudimentary vehicle for defining data semantics.

More recently, the XML Schema has been introduced to describe the structure of an XML document. An XML Schema has better support for applications, document structure, attributes, and data-typing. For example, here is the previous DTD transformed into an XML Schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="customer">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="first_name" type="xs:string"/>
        <xs:element name="middle_initial" type="xs:string"/>
        <xs:element name="last_name" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>

    <xs:complexType name="USAddress">
      <xs:sequence>
        <xs:element name="street" type="xs:string"/>
        <xs:element name="city"type="xs:string"/>
        <xs:element name="state"type="xs:string"/>
        <xs:element name="zip"type="xs:decimal"/>
      </xs:sequence>
      <xs:attribute name="country" type="xs:NMTOKEN"
       fixed="US"/>
    </xs:complexType>

  </xs:element>

</xs:schema>

Given the benefits of XML Schema over DTDs, more XML documents are adopting them for use in modern XML applications.

The important thing to remember about XML is that it solves a different problem than HTML. HTML is a markup language, but XML is a meta-language. In other words, XML is a language that generates other kinds of languages. The idea is to use XML to generate a language specifically tailored to each requirement you encounter. In short, XML enables designers to create their own customized tags, thereby enabling the definition, transmission, validation, and interpretation of data between applications and between organizations. So, the most important reason to learn XML is that it is quickly becoming the de facto standard for application interfaces.

There are, however, some issues with XML, the most troubling of which is market hype. There is plenty of confusion surrounding XML. Some believe that XML provides metadata where none currently exists, or that XML replaces SQL as a data access method for relational data. Neither of these assertions is true.

There is no way that any technology, XML included, can conjure up information that does not exist. People must create the metadata tags in XML for the data to be described. XML enables self-describing documents; it doesn’t describe your data for you.

Moreover, XML doesn’t perform the same functions as SQL. As a result, XML can’t replace it. As the standard access method for relational data, SQL DML is used to “telling” a relational DBMS what data is to be retrieved. XML, on the other hand, is a document description language that describes the basic contents of data. An XML schema can be associated with an XML document to type XML data. XML might be useful for defining databases but not for accessing them.

DB2, as well as most of the other popular DBMS products, now provides built-in support for native XML. By integrating XML into DB2 databases, you can more directly and quickly access the XML documents, as well as search and store entire XML documents using SQL. Integration can involve simply storing XML in a large VARCHAR or CLOB column, breaking down the XML into multiple columns in one or more DB2 tables, or more commonly to store XML data natively within a column of a DB2 table. As of DB2 V9, you can store XML data natively in a DB2 using pureXML, which allows you to define columns with a data type of XML.

Storing Data Relationally Versus as XML

Before delving into a discussion of how to store and access XML data natively in DB2 for z/OS, first take a moment to contrast the traditional row and column data of DB2 (and other relational database systems) versus XML data.

The self-describing data format of XML enables complex data to be stored in a single document without giving up the ability to query, search, or aggregate the data. And the XML definition (DTD or XML schema) can be modified without requiring any changes to the database schema. Of course, this may be viewed as a pro by some and a con by others. Developers will likely enjoy the added flexibility, whereas DBAs will likely lament the lack of control.

The flexible nature of XML can require more resources (CPU and I/O) to examine and interpret the XML data as opposed to accessing the same data in a traditional row and column format. But the complexity of the schema must be taken into consideration.

XML is often more suitable for applications with complex and variable data structures, and for combining structured and unstructured information. Relational row and column data is most suitable for stable data structures. A complex hierarchy stored in XML, for example, may be queried more efficiently than a similar hierarchy stored in traditional DB2 form. Relational data, though, can offer more query flexibility and optimization choices.

Keeping an XML document intact in an XML column has the advantage of maximum flexibility but can negatively impact performance.

Fully shredding an XML document into a relational format has the advantage of making high volume transactional processes run faster. But shredding has several disadvantages, as well: Converting the XML documents to the equivalent relational model can consume a lot of resources; converting relational data back into an XML document is expensive; and it can be difficult to keep up with changing requirements.

A hybrid approach in which some portions of the document are maintained as XML and other portions are shredded into relational can be a best practice approach both for performance and maintainability.

Objects having sparse attributes are another area in which XML offers an advantage over a traditional relational data format. When a large number of attributes are possible but most are not used by every instance, XML may be a better choice because every attribute would need to be defined and stored with traditional relational data. In relational data, columns might be NULL, but in XML those data items are just not present.

Consider, for example, a product catalog where each product may have a different number of attributes: size, color, weight, length, height, material, style, watts, voltage, resolution, and so on, depending upon the product. A relational approach with one column per attribute would require a large number of columns requiring NULL, which is not ideal. Alternative approaches, such as a table per product or a three-column table that stores name/value pairs for each product ID are equally unappealing. With an XML solution, elements and attributes can be optional, so they would be omitted when they do not apply for a specific product.

Often there are XML schemas already defined by some industry standard organization (for example, ISO). Using those schemas can greatly reduce the time and effort for design and data modeling. Also these schemata are often used for defining the data received or sent by an application. It is often desirable to store XML data redundantly (which is against good relational design) in a relational column or even a subset of the document in an XML column. If schema validation, a relatively costly process, can be done once, then portions of the XML document can be used in other tables without revalidating.

Parsing and serializing XML data also can be a costly process. If XML data is required to be passed as output, it can be beneficial to store those portions of the document redundantly as XML documents. Using some hybrid design approach combining relational and XML can be useful: Highly referenced fields are best in relational columns, whereas sparsely populated or seldom-referenced fields may be better left in XML columns.

At any rate, XML data has its place, and DB2 users are lucky that they can store XML data natively within DB2 databases.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020