Manipulating XML data - examples

After you create a nickname, you can query and manipulate XML data in the remote table or XML document on the federated system. The federated system supports all of the data manipulation operations for XML data that the database system supports.

The following examples show the different methods that you can use to work with XML data by using the nickname NNXML1.

Manipulating XML data with SQL

With SQL you can perform basic select, insert, update, and delete operations.

Example: Use the SELECT and INSERT statements to access and insert XML data from the nickname NNXML1.

In the following SELECT statement, the XML document is selected on the federated server:
In the following INSERT statement a string is inserted into a nickname XML column:
INSERT INTO NNXML1 (xmlcol) VALUES ('<a><b>My data</b></a>'); 

Manipulating XML data with SQL/XML functions

With SQL/XML functions, you can perform a range of operations that include querying, validating, and publishing XML data.

Example: Use the XMLVALIDATE function to validate XML data by using the XML schema that is obtained from the schema specification in the XML instance document:


Manipulating XML data with XQuery

You can use XQuery functions to manipulate XML data, such as the xmlcolumn function.

Example: Use XQuery to retrieve element b, which is a child of root a, from the XML column named XMLCOL:

xquery db2-fn:xmlcolumn('NNXML1.XMLCOL')/a/b;