The pureXML® feature
allows you to store well-formed XML documents in database table columns
that have the XML data type. By storing XML data in XML columns, the
data is kept in its native hierarchical form, rather than stored as
text or mapped to a different data model.
Because pureXML data
storage is fully integrated, the stored XML data can be accessed and
managed by leveraging existing DB2® database
server functionality.
The storage of XML data in its native hierarchical form enables
efficient search, retrieval, and updates of XML. XQuery, SQL, or a
combination of both can be used to query and update XML data. SQL
functions that return XML data or take XML arguments (referred to
as SQL/XML functions) also enable XML data to be constructed or published
from values retrieved from the database.
Querying
and updating
XML documents stored in XML columns can be
queried and updated using the following methods:
- XQuery
- XQuery is a generalized language for interpreting, retrieving,
and modifying XML data. The DB2 database
server allows XQuery to be invoked directly or from within SQL. Because
the XML data is stored in DB2
tables and views, functions are provided that extract the XML data
from specified tables and views by naming the table or view directly,
or by specifying an SQL query. XQuery supports various expressions
for processing XML data, for updating existing XML objects such as
elements and attributes, and for constructing new XML objects. The
programming interface to XQuery provides facilities similar to those
of SQL to execute queries and retrieve results.
- SQL statements and SQL/XML functions
- Many SQL statements support the XML data type. This enables you
to perform many common database operations with XML data, such as
creating tables with XML columns, adding XML columns to existing tables,
creating indexes over XML columns, creating triggers on tables with
XML columns, and inserting, updating, or deleting XML documents.
The set of SQL/XML functions, expressions, and specifications supported
by DB2 database server has been
enhanced to take full advantage of the XML data type.
XQuery can
be invoked from within an SQL query. In this case, the SQL query can
pass data to XQuery in the form of bound variables.
Application development
Support for application
development is provided by several programming languages, and through
SQL and external procedures:
- Programming language support
- Application development support of the new pureXML feature enables applications to combine
XML and relational data access and storage. The following programming
languages support the XML data type:
- C or C++ (embedded SQL or CLI)
- COBOL
- Java™ (JDBC or SQLJ)
- C# and Visual Basic (IBM® Data
Server Provider for .NET)
- PHP
- Perl
- SQL and external procedures
- XML data can be passed to SQL procedures and external procedures
by including parameters of data type XML in CREATE PROCEDURE parameter
signatures. Existing procedure features support the implementation
of procedural logic flow around SQL statements that produce or make
use of XML values as well as the temporary storage of XML data values
in variables.
Administration
The pureXML feature provides a repository for
managing the URI dependencies of XML documents and enables XML data
movement for database administration:
- XML schema repository (XSR)
- The XML schema repository (XSR) is a repository for all XML artifacts
required to
process XML instance documents stored in XML columns. It stores XML
schemas, DTDs, and external entities referenced in XML documents.
- Import, export and load utilities
- The import, export and load utilities have been updated to support
the native XML data type. These utilities treat XML data like LOB
data: both types of data are stored outside the actual table. Application
development support for importing, exporting and loading XML data
is also provided by updated db2Import, db2Export and db2Load APIs.
These updated utilities permit data movement of XML documents stored
in XML columns that is similar to the data movement support for relational
data.
Performance
Several performance oriented
features are available to you when working with XML documents stored
in XML columns:
- Indexes over XML data
- Indexing support is available for data stored in XML columns.
The use of indexes over XML data can improve the efficiency of queries
issued against XML documents. Similar to a relational index,
an index over XML
data indexes
a column. They differ, however, in that a relational index indexes
an entire column, while an index over XML
data indexes
part of a column. You indicate which parts of an XML column are indexed
by specifying an XML pattern, which is a limited XPath expression.
- Optimizer
- The optimizer has been updated to support the evaluation of SQL,
XQuery, and SQL/XML functions that embed XQuery, against XML and relational
data. The optimizer exploits statistics gathered over XML data, as
well as data from indexes over XML data, to produce efficient query
execution plans.
- Explain facility
- The Explain facility has been updated to support
SQL enhancements for querying XML data and to support XQuery expressions.
These updates to the Explain facility allow you to see quickly how DB2 database server evaluates query
statements against XML data.
Tooling
Support for
the XML data type is available in tools including the command line
processor, IBM Data Studio,
and IBM Database Add-Ins for Microsoft Visual Studio.
Annotated XML schema decomposition
The pureXML feature enables you
to store and access XML data as XML, in its hierarchical form, there
can be cases where accessing XML data as relational data is required.
Annotated XML schema decomposition decomposes documents based on annotations
specified in an XML schema.