DB2 10.5 for Linux, UNIX, and Windows

pureXML tutorial

You can use the pureXML® XML data type to define table columns so that you can store a single, well-formed XML document in each row. This tutorial demonstrates how to set up a DB2® database to store XML data and to perform basic operations with the pureXML feature.

Application programming languages such as C++, Java™, and PHP support the XML data type. You can write applications to store XML data in DB2 databases tables, retrieve data from tables, or call stored procedures or user-defined functions with XML parameters. For information about application programming language support, see the related reference at the end of this topic.

This tutorial is written for a single-partition database environment, however you can also use the pureXML feature in a partitioned database environment. See the related links for information about using pureXML in a partitioned database environment.

Prerequisites

In a DB2 command window, start the DB2 command-line processor by issuing the db2 -td~ command, the db2 command with the -td~ option.1

The -td option sets the tilde (~) as the statement termination character. Specifying a termination character other than the default semicolon (-t option) ensures that statements or queries that use namespace declarations are not misinterpreted, because namespace declarations are also terminated by a semicolon. The examples throughout this tutorial use the ~ termination character.

You can enter or copy and paste the examples in the lessions into the DB2 command-line processor, in interactive mode.

Namespaces: The XML documents used in the tutorial contain namespaces. When using XML documents that contain namespaces, all queries and associated operations that specify a namespace, such as creating an index over XML data by using the CREATE INDEX statement or querying XML data using an XQuery expression, must declare the same namespace to yield expected results. Declaring namespaces when using XML documents that contain namespaces is standard namespace behavior.
1 On Windows operating systems, use the db2cmd command to start a DB2 command window before issuing the db2 -td~ command.