Purexml Guide
Total Page:16
File Type:pdf, Size:1020Kb
IBM DB2 10.5 for Linux, UNIX, and Windows pureXML Guide SC27-5521-00 IBM DB2 10.5 for Linux, UNIX, and Windows pureXML Guide SC27-5521-00 Note Before using this information and the product it supports, read the general information under Appendix E, “Notices,” on page 501. Edition Notice This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. You can order IBM publications online or through your local IBM representative. v To order publications online, go to the IBM Publications Center at http://www.ibm.com/shop/publications/ order v To find your local IBM representative, go to the IBM Directory of Worldwide Contacts at http://www.ibm.com/ planetwide/ To order DB2 publications from DB2 Marketing and Sales in the United States or Canada, call 1-800-IBM-4YOU (426-4968). When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © Copyright IBM Corporation 2006, 2013. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About this book ...........vii Displaying detailed XML parsing and validation errors...............55 Chapter 1. pureXML overview -- DB2 as ErrorLog XML schema definition for enhanced an XML database ...........1 error message support ..........57 Using XML in a non-Unicode database .....60 XML data type .............3 XML input and output overview .......3 Chapter 5. Querying XML data ....65 Comparison of the XML model and the relational model ................8 Introduction to XQuery ..........65 XQuery and XPath data model ........10 Retrieving DB2 data with XQuery functions . 66 Sequences and items ..........10 Introduction to querying XML data with SQL . 67 Atomic values ............11 Comparison of XQuery to SQL ........68 Node hierarchies ...........11 Comparison of methods for querying XML data . 69 Node properties ............13 Specifying XML namespaces.........70 Node kinds .............13 Example: Changing the namespace prefix of an Document order of nodes.........15 element................72 Node identity ............16 XMLQUERY function overview........73 Typed values and string values of nodes . 16 Non-empty sequences returned by XMLQUERY 74 Tools that support XML ..........16 Empty sequences returned by XMLQUERY . 75 Federation support for pureXML .......18 Casting of XMLQUERY results to non-XML types 76 Replication and event publishing support for Casting between data types ........77 pureXML ...............19 XMLQUERY .............85 Articles on XML support ..........19 XMLTABLE function overview ........87 Example: Inserting values returned from Chapter 2. pureXML tutorial......21 XMLTABLE .............89 Example: Returning one row for each occurrence Lesson 1: Creating a DB2 database and table that of an item using XMLTABLE .......90 can store XML data............22 Example: Processing elements from multiple trees Lesson 2: Creating indexes over XML data ....22 in an XML document using XMLTABLE ....92 Lesson 3: Inserting XML documents into XML type Example: Processing hierarchical data using columns ...............23 XMLTABLE .............94 Lesson 4: Updating XML documents stored in XML XMLTABLE .............95 columns ...............24 XMLEXISTS predicate when querying XML data . 99 Lesson 5: Deleting XML data ........25 XMLEXISTS predicate usage .......100 Lesson 6: Querying XML data ........27 XMLEXISTS predicate .........101 Lesson 7: Validating XML documents against XML Passing parameters between SQL statements and schemas ...............30 XQuery expressions ...........104 Lesson 8: Transforming with XSLT stylesheets . 31 Constant and parameter marker passing to XMLEXISTS and XMLQUERY .......104 Chapter 3. XML storage .......35 Simple column name passing with XMLEXISTS, XML storage object ............35 XMLQUERY, or XMLTABLE .......105 XML base table row storage .........36 Passing parameters from XQuery to SQL . 106 Storage requirements for XML documents ....37 Data retrieval with XQuery.........107 Data types for archiving XML documents ....38 Guidelines for matching indexes with queries overview ...............109 Chapter 4. Inserting XML data .....39 Restrictiveness of index definitions .....110 Creation of tables with XML columns......39 Considerations when specifying text() nodes . 112 Addition of XML columns to existing tables . 40 Data type of literals ..........113 Insertion into XML columns .........40 Join predicate conversion ........114 XML parsing ..............41 Indeterminate query evaluation ......115 XML data integrity ............46 Full-text search in XML documents ......116 Check constraints on XML columns .....46 Retrieval of data in XML columns to earlier DB2 Trigger processing of XML data.......48 clients ................117 XML validation ............50 SQL/XML publishing functions for constructing XSR_GET_PARSING_DIAGNOSTICS stored XML values ..............118 procedure ..............53 Examples of publishing XML values .....119 © Copyright IBM Corp. 2006, 2013 iii Special character handling in SQL/XML Registering XSR objects through the command publishing functions ..........123 line processor ............207 XML serialization ...........124 Java support for XML schema registration and Transforming with XSLT stylesheets ......125 removal ..............208 Passing parameters to XSLT stylesheets at Altering registered XSR objects .......210 runtime ..............128 Evolving an XML schema ........210 Example: Using XSLT as a formatting engine 128 Compatibility requirements for evolving an Example: Using XSLT for data exchange . 130 XML schema ............211 Example: Using XSLT to remove namespaces 131 Scenario: Evolving an XML schema .....218 Example: Using the document function of XSLT 134 Examples of extracting XML schema information 220 Important considerations for transforming XML Listing XML schemas registered with the XSR 220 documents .............136 Retrieving all components of an XML schema Differences in an XML document after storage and registered with the XSR .........220 retrieval ...............136 Retrieving the XML schema of an XML document .............221 Chapter 6. Indexing XML data ....139 Index XML pattern expressions .......140 Chapter 9. XML data movement . 223 Examples of using case insensitive XML indexes 143 Important considerations for XML data movement 224 Examples of using indexes that specify fn:exists 145 Query and XPath Data Model ........225 Examples of using indexes with queries that LOB and XML file behavior when importing and specify fn:starts-with ..........148 exporting...............225 Context steps and function expression steps . 150 XML data specifier ...........226 XML namespace declarations ........150 Exporting XML data ...........227 Data types associated with index XML pattern Importing XML data ...........230 expressions ..............152 Loading XML data ...........231 Data type conversion for indexes over XML data 153 Resolving indexing errors when loading XML Invalid XML values ..........154 data ...............232 Document rejection or CREATE INDEX statement failure ...........156 Chapter 10. Application programming Summary table for conversion to the index XML language support .........239 data type ..............157 CLI.................240 XML schemas and index key generation ....158 XML data handling in CLI applications - UNIQUE keyword semantics ........159 Overview..............240 Database objects associated with XML data XML column inserts and updates in CLI indexing ...............160 applications .............241 Logical and physical indexes over XML data 160 XML data retrieval in CLI applications ....242 Other database objects associated with XML Changing of default XML type handling in CLI columns ..............161 applications .............243 Recreation of indexes over XML data ....162 Embedded SQL ............243 CREATE INDEX ............163 Declaring XML host variables in embedded SQL Sample queries against indexes over XML data . 185 applications .............243 Restrictions on indexes over XML data .....188 Example: Referencing XML host variables in Common XML indexing issues .......190 embedded SQL applications .......245 Troubleshooting SQL20305N messages issued by Executing XQuery expressions in embedded INSERT or UPDATE statements ......191 SQL applications ...........246 Troubleshooting SQL20306N messages issued by Recommendations for developing embedded CREATE INDEX statements on populated tables 193 SQL applications with XML and XQuery . 247 Identifying XML values in an SQLDA ....248 Chapter 7. Updating XML data ....197 Java ................248 Use of updating expressions in a transform Binary XML format in Java applications . 248 expression ..............198 JDBC ...............250 Updating XML documents with information from SQLJ ...............258 other tables ..............201 PHP................263 Deletion of XML data from tables ......202 PHP application development for IBM Database servers ..............263 Chapter 8. XML schema repository 205 XML data retrieval using PHP applications . 263 XSR objects ..............205 PHP downloads and related resources ....264 XSR object registration ..........205 Perl ................264 Registering