Your SlideShare is downloading. ×
XML Support in DB2 V9
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

XML Support in DB2 V9

1,190

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,190
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. TRAINING & CONSULTING XML Support in DB2 V9 Dutch DB2 User Group (DDUG), 09/10/2007 Ludo Van den dries ABIS Training & Consulting www.abis.be training@abis.be 2007 Document number: DB2_XML_01.fm 10 October 2007 Address comments concerning the contents of this publication to: ABIS Training & Consulting, P.O. Box 220, B-3000 Leuven, Belgium Tel.: (+32)-16-245610, Fax: (+32)-16-245639 © Copyright ABIS N.V.
  • 2. XML Support in DB2 V9 • the wonders of XML • the wonders in DB2 V9 ABIS Training & Consulting 1
  • 3. >>> XML basics 1 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • XML = Extensible Markup Language 3. Namespaces 4. XML-based standards • a universal way of structuring text documents 5. Parsing 6. Transforming 7. Searching • XML 1.0 (1998/2000) 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< • from World Wide Web Consortium (W3C) 11. INSERTing XML 12. SHREDDING 13. UPDATEing • markup language, cf. SGML, HTML, ... 14. >> Four ways to query XML in DB2 • objectives: 15. Plain SQL 16. SQL/XML independent, interoperable, simple, human readable, ... 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 2
  • 4. XML document XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document <?xml version="1.0" encoding="UTF-8"?> structure 3. Namespaces <bestsellers> 4. XML-based standards 5. Parsing <book> 6. Transforming 7. Searching <bookTitle>Design Patterns Explained</bookTitle> 8. Storing <authorList> 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< <author>Alan Shalloway</author> <author>James R. Trott</author> 11. INSERTing XML 12. SHREDDING </authorList> 13. UPDATEing 14. >> Four ways to query XML <publicationInfo> in DB2 15. Plain SQL <publisher>Addison-Wesley</publisher> <year>2001</year> 16. SQL/XML </publicationInfo> 17. XQuery 18. XQuery with embedded SQL <ISBN>0-201-71594-5</ISBN> 19. >> Optimization 20. Epilogue: When to store </book> XML in the database <book> <bookTitle>Java and Web Services</bookTitle> <authorList> <author>R. Brunner</author> </authorList> <publicationInfo> <publisher>SAMS</publisher> </publicationInfo> <ISBN>0-672-32363-X</ISBN> </book> </bestsellers> XML Support in DB2 V9 ABIS 3
  • 5. XML document (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure bestsellers 3. Namespaces 4. XML-based standards 5. Parsing 6. Transforming 7. Searching book book 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING bookTitle authorList publicationInfo bookTitle authorList publicationInfo 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML Design Patterns Explained author author publisher year Java and Web Services author publisher 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization Alan Shalloway James R. Trott Addison-Wesley 2001 R. Brunner SAMS 20. Epilogue: When to store XML in the database • structured text content • document = tree, varying composition • user defined tags (> extensible) • elements, root element, whitespace • simple construction (> well-formedness) XML Support in DB2 V9 ABIS 4
  • 6. Unicode XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces One single character set (see www.unicode.org) 4. XML-based standards 5. Parsing 6. Transforming 7. Searching 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 5
  • 7. Unicode (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Several encodings: 4. XML-based standards 5. Parsing 6. Transforming • UTF-16 (2 / 4 bytes) 7. Searching 8. Storing • UTF-8 (from 1 to 4 bytes) 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML • ISO-8859-x (1-byte) 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML • etc... in DB2 15. Plain SQL 16. SQL/XML 17. XQuery Encoding indicated in xml declaration: 18. XQuery with embedded SQL 19. >> Optimization <?xml version="1.0" encoding="UTF-8"?> 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 6
  • 8. More nodes & trees XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document <?xml version="1.0" encoding="UTF-8"?> structure 3. Namespaces <?myProg blablabla ?> 4. XML-based standards 5. Parsing <Enrolments> 6. Transforming 7. Searching <!-- here is some comment --> 8. Storing <Enrolment nr=”17” source=”web”> 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< <Course>Java and XML</Course> 11. INSERTing XML 12. SHREDDING <Student> 13. UPDATEing 14. >> Four ways to query XML <FirstName>Mary</FirstName> in DB2 15. Plain SQL <LastName>Jones</LastName> 16. SQL/XML <Company>Nepsis</Company> 17. XQuery 18. XQuery with embedded SQL </Student> 19. >> Optimization 20. Epilogue: When to store <InvoiceDetails> XML in the database <Price currency=”USD”>350</Price> <Enroller> .... ... </Enrolment> <Enrolment>... attributes, processing instruction, comment, node tree, root node (/) XML Support in DB2 V9 ABIS 7
  • 9. XML Document (..) XML Support in DB2 V9 1. >>> XML basics <PLAY> 2. Defining/imposing document structure <TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE> 3. Namespaces <PERSONAE> 4. XML-based standards <TITLE>Dramatis Personae</TITLE> 5. Parsing 6. Transforming <PERSONA>CLAUDIUS, king of Denmark.</PERSONA> 7. Searching <PERSONA>HAMLET, son to the late, and nephew to the present king.</PERSONA> 8. Storing <PERSONA>POLONIUS, lord chamberlain.</PERSONA> 9. Ubiquitous XML <PGROUP> 10. >>> XML in DB2 V9 <<< 11. INSERTing XML <PERSONA>VOLTIMAND</PERSONA> 12. SHREDDING <PERSONA>CORNELIUS</PERSONA> 13. UPDATEing <PERSONA>ROSENCRANTZ</PERSONA> 14. >> Four ways to query XML <GRPDESCR>courtiers.</GRPDESCR> in DB2 15. Plain SQL </PGROUP> 16. SQL/XML ... 17. XQuery <SPEECH> 18. XQuery with embedded SQL 19. >> Optimization <SPEAKER>LORD POLONIUS</SPEAKER> 20. Epilogue: When to store <LINE>I hear him coming: let's withdraw, my lord.</LINE> XML in the database </SPEECH> <STAGEDIR>Exeunt KING CLAUDIUS and POLONIUS</STAGEDIR> <STAGEDIR>Enter <PERSONA>HAMLET</PERSONA>, heavily in doubt. </STAGEDIR> <SPEECH> <SPEAKER>HAMLET</SPEAKER> <LINE>To be, or not to be: that is the question:</LINE> <LINE>Whether 'tis nobler in the mind to suffer</LINE> <LINE>The slings and arrows of outrageous fortune,</LINE> <LINE>Or to take arms against a sea of troubles,</LINE> ... ... </PLAY> XML Support in DB2 V9 ABIS 8
  • 10. XML Document (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document <document> structure 3. Namespaces <body> 4. XML-based standards 5. Parsing <heading style=”head20_1”>Objectives </heading> 6. Transforming 7. Searching <paragraph style=”simple”>This course consists of 2 parts.</paragraph> 8. Storing <paragraph style=”simple”>In the first part, participants will become familiar with 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< the Enterprise Java (J2EE) platform, the basis for the WebSphere architecture. The 11. INSERTing XML integration of Java with existing (enterprise) systems is also covered. 12. SHREDDING 13. UPDATEing ... 14. >> Four ways to query XML in DB2 </document> 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 9
  • 11. Defining/imposing document structure 2 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Two standards: 4. XML-based standards 5. Parsing 6. Transforming • DTD (Document Type Definition) 7. Searching 8. Storing • XML Schema 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING A set of rules 13. UPDATEing 14. >> Four ways to query XML defining what specific documents should contain on which place in DB2 (mandatory and optional things). 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL Can be used to 19. >> Optimization 20. Epilogue: When to store XML in the database • validate a document: does it follow the specific rules? • guide you while composing/editing a document • ... Note: well-formedness vs. validity XML Support in DB2 V9 ABIS 10
  • 12. DTD example XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document <?xml version="1.0" encoding="UTF-8"?> structure 3. Namespaces <!DOCTYPE bestsellers SYSTEM "E:XMLBooks.dtd"> 4. XML-based standards 5. Parsing <bestsellers> 6. Transforming 7. Searching <book> 8. Storing <bookTitle>Design Patterns Explained</bookTitle> 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< <authorList> 11. INSERTing XML 12. SHREDDING <author>Alan Shalloway</author> 13. UPDATEing 14. >> Four ways to query XML ... in DB2 15. Plain SQL </bestsellers> 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL --------------------------------------------------------------------------------------------- 19. >> Optimization 20. Epilogue: When to store XML in the database <!ELEMENT bestsellers (book+)> <!ELEMENT book (bookTitle, authorList, publicationInfo, ISBN)> <!ELEMENT bookTitle (#PCDATA)> <!ELEMENT authorList (author+)> <!ELEMENT author (#PCDATA)> <!ELEMENT publicationInfo (publisher, year?)> <!ELEMENT publisher (#PCDATA)> <!ELEMENT year (#PCDATA)> <!ELEMENT ISBN (#PCDATA)> XML Support in DB2 V9 ABIS 11
  • 13. Schema Example XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> structure 3. Namespaces <xs:element name="bestsellers"> 4. XML-based standards 5. Parsing <xs:complexType> 6. Transforming 7. Searching <xs:sequence> 8. Storing <xs:element name="book" maxOccurs="unbounded"> 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< <xs:complexType> 11. INSERTing XML 12. SHREDDING <xs:sequence> 13. UPDATEing 14. >> Four ways to query XML <xs:element name="bookTitle" type="xs:string"/> in DB2 15. Plain SQL <xs:element name="authorList" > 16. SQL/XML <xs:complexType> 17. XQuery 18. XQuery with embedded SQL <xs:sequence> 19. >> Optimization 20. Epilogue: When to store <xs:element name="author" maxOccurs="unbounded"/> XML in the database </xs:sequence> </xs:complexType> </xs:element> <xs:element name="publicationInfo" > <xs:complexType> <xs:sequence> <xs:element name="publisher" type="xs:string"/> <xs:element name="year" type="xs:string" minOccurs=... etc ... XML Support in DB2 V9 ABIS 12
  • 14. XML Schema (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XML by itself! 4. XML-based standards 5. Parsing 6. Transforming 7. Searching Powerful definition of 8. Storing 9. Ubiquitous XML • complex structures 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING • data types 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database Note: document < > schema XML Support in DB2 V9 ABIS 13
  • 15. Namespaces 3 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Namespace = vocabulary as defined by 1 or more schemas 4. XML-based standards 5. Parsing 6. Transforming http://www.sas.com/course 7. Searching person 8. Storing course 9. Ubiquitous XML firstName 10. >>> XML in DB2 V9 <<< name 11. INSERTing XML duration person 12. SHREDDING course 13. UPDATEing 14. >> Four ways to query XML name title in DB2 15. Plain SQL duration 16. SQL/XML http://www.abis.be 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization <courseList xmlns:abis="http://www.abis.be" xmlns:sas="www.sas.com/course"> 20. Epilogue: When to store XML in the database <abis:course> <abis:name>XML basics</abis:name> <abis:duration>3</abis:duration> </abis:course> <sas:course> <sas:title>XML and SAS</sas:title> </sas:course> <abis:course> etc ..... XML Support in DB2 V9 ABIS 14
  • 16. XML-based standards 4 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Many auxiliary/derived/applied standards 4. XML-based standards 5. Parsing 6. Transforming • Basic (W3C): 7. Searching 8. Storing - XSLT & Xpath 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML - XQuery 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML - XLink & XPointer in DB2 15. Plain SQL • Horizontal application: 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL - SVG (Scalable Vector Graphics) 19. >> Optimization 20. Epilogue: When to store XML in the database - SMIL (Synchronized Multimedia Integration Language) - RSS / Atom • Vertical application (cf. OASIS, xml.org) : - XBRL (Extensible Business Reporting Language) - HR-XML (Human Resources) - GML (Geography Markup Language) XML Support in DB2 V9 ABIS 15
  • 17. Parsing 5 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Parsing = getting logical tree data out/in physical XML text 4. XML-based standards 5. Parsing 6. Transforming 7. Searching Applications leave this task to specialized ‘parsers’ 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< Most popular standard APIs for XML parsers: DOM and SAX 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery XML 18. XQuery with embedded SQL application parser document 19. >> Optimization (DOM or 20. Epilogue: When to store SAX) XML in the database E.g. Microsoft MSXML Java Xerces XML Support in DB2 V9 ABIS 16
  • 18. Transforming 6 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XSL = eXtensible Stylesheet Language 4. XML-based standards 5. Parsing 6. Transforming 7. Searching Aspects: 8. Storing 9. Ubiquitous XML • transformation recipe (XSLT) 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING • formatting for rendition (XSL-FO) 13. UPDATEing 14. >> Four ways to query XML in DB2 • accessing the underlying XML structure (XPath) 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 17
  • 19. XSLT XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XSL stylesheet: 4. XML-based standards 5. Parsing 6. Transforming • patterns to search in input document 7. Searching 8. Storing • templates to produce the output document 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML • is XML itself (of course...) 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL XML 19. >> Optimization Document 20. Epilogue: When to store XML in the database XSL StyleSheet XSLT Processor XML, HTML, COBOL, Java, text, ... XML Support in DB2 V9 ABIS 18
  • 20. Searching 7 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XPath: 4. XML-based standards 5. Parsing 6. Transforming • locating information inside a document 7. Searching 8. Storing • for query, pointing, linking, transformation, schema, ... 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING XMLQuery (aka XQuery): 13. UPDATEing 14. >> Four ways to query XML in DB2 • powerful querying in document & entire XML databases 15. Plain SQL 16. SQL/XML 17. XQuery • emerging standard, many predecessors... 18. XQuery with embedded SQL 19. >> Optimization • query only 20. Epilogue: When to store XML in the database Versions: • XPath 1.0 + XSLT 1.0 (1999) • XPath 2.0 + XSLT 2.0 + XQuery 1.0 (2007) XSLT versus XQuery: competing standards? XML Support in DB2 V9 ABIS 19
  • 21. XPath XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Locating things in a tree 4. XML-based standards 5. Parsing 6. Transforming 7. Searching Result = node-set, boolean, string, number 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< One step: 11. INSERTing XML 12. SHREDDING 13. UPDATEing • axis::node-test[predicate][predicate][...] 14. >> Four ways to query XML in DB2 child::Person[position()=3] 15. Plain SQL 16. SQL/XML descendant::Book[attribute::number=”55”] 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store Complete location path: XML in the database • step1 / step2 / step3 / ... PersonList/Person[@nr=”55”]/FirstName XML Support in DB2 V9 ABIS 20
  • 22. XPath (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Example 4. XML-based standards 5. Parsing / 6. Transforming 7. Searching 8. Storing PersonList 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING 13. UPDATEing Person Person Person 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery FirstName LastName Salary FirstName LastName Salary Name Salary 18. XQuery with embedded SQL 19. >> Optimization John Brussel 12000 Ann Van Halen 24000 15000 20. Epilogue: When to store XML in the database FirstName LastName Josette 's Meyers XML Support in DB2 V9 ABIS 21
  • 23. XPath axis XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces 4. XML-based standards 5. Parsing 6. Transforming 7. Searching 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 22
  • 24. XSLT vs. XQuery (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XSLT 4. XML-based standards 5. Parsing <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 6. Transforming 7. Searching <xsl:template match="bestsellers"> 8. Storing 9. Ubiquitous XML <authorList> 10. >>> XML in DB2 V9 <<< <xsl:apply-templates select="//book[@category=’fiction’"/> 11. INSERTing XML 12. SHREDDING </authorList> 13. UPDATEing 14. >> Four ways to query XML </xsl:template> in DB2 15. Plain SQL <xsl:template match="book"> 16. SQL/XML 17. XQuery <xsl:copy-of select="descendant::author"/> 18. XQuery with embedded SQL </xsl:template> 19. >> Optimization 20. Epilogue: When to store </xsl:stylesheet> XML in the database XQuery: FLWOR (for, let, where, order by, return) <authorList> { for $b in document(‘bestsellers.xml’)/bestsellers/book where $b/@category=’fiction’ return $b//author } </authorList> XML Support in DB2 V9 ABIS 23
  • 25. Storing 8 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Main options: 4. XML-based standards 5. Parsing 6. Transforming • simply as files (*.XML) 7. Searching 8. Storing • in native XML database: 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML - added support e.g. for querying, transforming, linking 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML - Tamino, X-Hive, XIS ... in DB2 15. Plain SQL • in XML-enabled ‘conventional’ RDBMS 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL - DB2, Oracle, SQL Server, ... 19. >> Optimization 20. Epilogue: When to store XML in the database - diverse techniques: · stuffing into CLOBs & BLOBs · shredding into colums & tables - XML as ‘second-class’ data XML Support in DB2 V9 ABIS 24
  • 26. Storing XML in DB2 V9 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces pureXML (Viper) 4. XML-based standards 5. Parsing 6. Transforming 7. Searching DB2 as the hybrid database 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML: first-class data & first-class queries hybrid storage model -- transparent XML Support in DB2 V9 ABIS 25
  • 27. pureXML (..) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document CREATE DATABASE test USING CODESET utf-8 TERRITORY US structure 3. Namespaces 4. XML-based standards 5. Parsing CREATE TABLE orders (oid INT, otype CHAR(2), ocustomer XML, oinfo XML) 6. Transforming 7. Searching 8. Storing INSERT INTO orders (oid, otype, ocustomer, oinfo) VALUES (5, ‘EX’, 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< ‘<customer><firstname>John</firstname><lastname>Williams</lastname></customer>’, 11. INSERTing XML 12. SHREDDING ‘<order> 13. UPDATEing 14. >> Four ways to query XML <orderdate>2006-07-07</orderdate> in DB2 15. Plain SQL <shipnote>Fragile Contents</shipnote> 16. SQL/XML </order>’ 17. XQuery 18. XQuery with embedded SQL ); 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 26
  • 28. Ubiquitous XML 9 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XML is used/usable for many purposes: 4. XML-based standards 5. Parsing 6. Transforming • document oriented and ‘data’ oriented data 7. Searching 8. Storing • storage and import/export/transport 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML • content management 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML • transformation, rendering, publishing in DB2 15. Plain SQL • user interfaces (Web, HTML, WML, ...) 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL • configuration files 19. >> Optimization 20. Epilogue: When to store XML in the database • descriptive programming • Web Services ( > SOA) • RSS, Atom, ... Tools: dedicated (XMLSpy) <> integrated (WSAD, RAD, XML Developer Work- bench, ..., Visual Studio .NET, ...) XML Support in DB2 V9 ABIS 27
  • 29. >>> XML in DB2 V9 <<< 10 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Following topics will be illustrated: 4. XML-based standards 5. Parsing 6. Transforming • inserting & updateing XML 7. Searching 8. Storing • ways to query XML 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML • optimization 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 28
  • 30. INSERTing XML 11 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • the TRADITIONAL way! 3. Namespaces 4. XML-based standards - inserting a document 5. Parsing 6. Transforming 7. Searching - copying a document form an existing table 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< - constructing a document using appropriate functions 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML INSERT INTO customer (id, name) in DB2 15. Plain SQL VALUES (102, 16. SQL/XML XMLDOCUMENT(XMLELEMENT(name "CustomerName", 'De Greef'))); 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store INSERT INTO customer (id, name) XML in the database VALUES (101, (SELECT name FROM old_customers WHERE id = 1)); • PARSING is implicit! - invoked automatically to check document is ‘well-formed’ - to be invoked manually if whitespace in the XML document has to be preserved default behaviour: do not preserve! XML Support in DB2 V9 ABIS 29
  • 31. INSERTing XML (ii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • XML document validation 3. Namespaces 4. XML-based standards - requires an EXISTING schema, i.e. schema needs to be REGIS- 5. Parsing 6. Transforming TERED [XSD can be dropped, not updated] 7. Searching 8. Storing stored in a XML schema repository (XSR) - DB2 catalog tables 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML - procedure: 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML · register the primary schema, using: in DB2 15. Plain SQL -> fully qualified name for the schema file 16. SQL/XML 17. XQuery -> SQL identifier 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database register xmlschema http://customer from D:xsdcustomer.xsd as customer.xsd · register ‘dependant’ XSDs, ie. XSDs included/imported into the pri- mary one registered above · complete the registration: checks for content of XSD, well-formed- ness, ... complete xmlschema customer.xsd XML Support in DB2 V9 ABIS 30
  • 32. INSERTing XML (iii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure - validation requires invocation of the XMLVALIDATE function, 3. Namespaces to verify: 4. XML-based standards 5. Parsing 6. Transforming · node types 7. Searching 8. Storing · default values 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< · multiple occurrences 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL INSERT INTO customer (id, doc) 16. SQL/XML 17. XQuery VALUES (105, XMLVALIDATE (XMLPARSE (DOCUMENT 18. XQuery with embedded SQL 19. >> Optimization '<Name>DeGreef</Name>') 20. Epilogue: When to store XML in the database ACCORDING TO XMLSCHEMA ID customer.xsd)) XML Support in DB2 V9 ABIS 31
  • 33. SHREDDING 12 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces XML data can be SHRED into relational tables 4. XML-based standards 5. Parsing XML is a ‘received’ message 6. Transforming 7. Searching 8. Storing Its content has to be stored in relational tables 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< - use annotated XML schema doc to describe SHREDding rules, ie. 11. INSERTing XML 12. SHREDDING relate XML to relational structures, e.g. 13. UPDATEing 14. >> Four ways to query XML · tables to be used in DB2 15. Plain SQL 16. SQL/XML · dataypes of columns in the tables 17. XQuery 18. XQuery with embedded SQL · ... 19. >> Optimization 20. Epilogue: When to store XML in the database - register the schema (cfr.above), indicating the schema will be used for decomposition - invoke the decompose command XML Support in DB2 V9 ABIS 32
  • 34. UPDATEing 13 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Two ways: 4. XML-based standards 5. Parsing 6. Transforming • SQL UPDATE: the full XML column! 7. Searching 8. Storing • supplied stored procedure (DB2XMLFUNCTIONS.XMLUPDATE) 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING XMLUPDATE: 13. UPDATEing 14. >> Four ways to query XML in DB2 - partial updates to the document in a XML column 15. Plain SQL 16. SQL/XML 17. XQuery - using the stored procedure, supply: 18. XQuery with embedded SQL 19. >> Optimization · the full XML column to be updated 20. Epilogue: When to store XML in the database · the XML elements/attributes (in the doc in the column) to be inserted/updated/deleted XML Support in DB2 V9 ABIS 33
  • 35. >> Four ways to query XML in DB2 14 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces ‘Pure’: 4. XML-based standards 5. Parsing 6. Transforming • plain SQL 7. Searching 8. Storing • plain XQuery 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING ‘Blended’: 13. UPDATEing 14. >> Four ways to query XML in DB2 • SQL/XML ( = SQL with XPath/XQuery inside) 15. Plain SQL 16. SQL/XML 17. XQuery • XQuery with SQL inside 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 34
  • 36. Plain SQL 15 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document select ocustomer structure 3. Namespaces from orders 4. XML-based standards 5. Parsing where oid = 5; 6. Transforming 7. Searching 8. Storing select oinfo 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< from orders 11. INSERTing XML 12. SHREDDING where otype in (‘XE’, ‘AB’); 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL • use when: 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL - full document retrieval - no fragments required 19. >> Optimization 20. Epilogue: When to store XML in the database - search criteria on non-XML columns - insert, update, delete of full documents • why not use CLOB, VARCHAR? • DB2 Net search extender available in plain SQL, combined with e.g. Xpath expressions relational predicates - insert, update, delete - parameter markers - full text search function calls XML Support in DB2 V9 ABIS 35
  • 37. SQL/XML 16 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces SQL language standard: 4. XML-based standards 5. Parsing 6. Transforming - defines the XML datatype 7. Searching 8. Storing - defines functions for manipulating XML data: 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML · v8 [rel data => XML] : 12. SHREDDING xmlelement, xmlattribute, xmlforest, ... 13. UPDATEing 14. >> Four ways to query XML in DB2 · v9 [use Xquery, Xpath in SQL] : 15. Plain SQL xmlquery, xmltable, xmlexists 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database INSERT INTO nss (id, doc) VALUES (999, XMLDOCUMENT( XMLELEMENT (name "Name", XMLATTRIBUTES ('MALE' as "gender"), XMLFOREST ('Steve' as "FirstName", 'Ferrington' as "LastName")))); select oinfo from orders o where xmlexists(‘$o//order[orderdate = “2006-07-07”]’ passing o.oinfo as “o’); XML Support in DB2 V9 ABIS 36
  • 38. XMLTable XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Function that ‘converts’ a XML document into a table structure, ie: 4. XML-based standards 5. Parsing 6. Transforming - input: an XQuery expression 7. Searching 8. Storing - output: a table containing columns of any SQL type 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING Conclusion: generates a relational view into XML documents! 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL (cf. shredding < > publishing) 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization Views! 20. Epilogue: When to store XML in the database SELECT id, firstname, lastname, zipcode FROM xps, XMLTABLE( 'for $cust in $d/Customer return $cust' passing xps.doc as "d" COLUMNS firstname VARCHAR(20) path 'Name/FirstName/text()', lastname VARCHAR(20) path 'Name/LastName/text()', zipcode VARCHAR(10) path 'Address/Zip/text()') as nameszip WHERE zipcode = '95030' XML Support in DB2 V9 ABIS 37
  • 39. SQL/XML (iii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • advantages 3. Namespaces 4. XML-based standards - integration/interaction between SQL and XML based criteria 5. Parsing 6. Transforming 7. Searching · join based on XML and column criteria 8. Storing 9. Ubiquitous XML · ‘group by’ only implemented using SQL/XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING - full-text search condition supported 13. UPDATEing 14. >> Four ways to query XML in DB2 - use of parameter markers 15. Plain SQL 16. SQL/XML • disadvantages 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization - difficult for transformation purposes, yet ... 20. Epilogue: When to store XML in the database xsltransform (-> XSLT stylesheet based transformation) XML predicates - relational predicates - combining predicates - join (XML & relational, XML & XML) - insert, update, delete - parameter markers - XML aggregation, grouping - full text search function calls XML Support in DB2 V9 ABIS 38
  • 40. XQuery 17 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces All DB2 APIs support XQuery: 4. XML-based standards 5. Parsing 6. Transforming - CLI/ODBC (including therefore db2clp) 7. Searching 8. Storing - embedded SQL 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML - JDBC 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML - .Net in DB2 15. Plain SQL 16. SQL/XML 17. XQuery xquery 18. XQuery with embedded SQL for $order in db2-fn:xmlcolumn(“ORDERS.OINFO”)/order 19. >> Optimization 20. Epilogue: When to store where $order/orderdate=”2006-07-07” XML in the database return $order/shipnote; xquery <ul> { for $y in db2-fn:xmlcolumn('CLIENTS.CONTACTINFO')/Client/Address order by $y/zip return <li>{$y}</li> } </ul> XML Support in DB2 V9 ABIS 39
  • 41. XQuery (ii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • advantages 3. Namespaces 4. XML-based standards - XML only apps; no SQL, relational constructs required 5. Parsing 6. Transforming 7. Searching - easy to embed in XML documents to be created 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< - join, union XML documents 11. INSERTing XML 12. SHREDDING 13. UPDATEing • disadvantages 14. >> Four ways to query XML in DB2 - no DB2 Net search extender support 15. Plain SQL 16. SQL/XML 17. XQuery - no support for parameter markers - yet 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store - no support for UDFs XML in the database XML predicates - join (XML & XML) - transforming XML XML Support in DB2 V9 ABIS 40
  • 42. XQuery with embedded SQL 18 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Purpose: embed SQL in XML (aka XQuery) 4. XML-based standards 5. Parsing 6. Transforming 7. Searching XQUERY 8. Storing 9. Ubiquitous XML for $order in db2-fn:sqlquery(“select order from orders where otype=’EX’“)/id 10. >>> XML in DB2 V9 <<< where $order/orderdate=”2006-07-07” 11. INSERTing XML 12. SHREDDING return $order/shipnote; 13. UPDATEing 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML Support in DB2 V9 ABIS 41
  • 43. XQuery with embedded SQL (ii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure • advantages 3. Namespaces 4. XML-based standards - based on a valid SQL query 5. Parsing 6. Transforming 7. Searching - DB2 Net search extender supported 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< - integration/interaction between SQL and XML based criteria 11. INSERTing XML 12. SHREDDING 13. UPDATEing - parameter marker support 14. >> Four ways to query XML in DB2 - UDF support 15. Plain SQL 16. SQL/XML 17. XQuery 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database XML predicates - relational predicates - combining predicates - join (XML & relational, XML & XML) - XML aggregation, grouping - full text search function calls XML Support in DB2 V9 ABIS 42
  • 44. >> Optimization 19 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces New in DB2 v9: 2 language parsers 4. XML-based standards 5. Parsing · XQuery 6. Transforming 7. Searching 8. Storing · SQL 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< 11. INSERTing XML Result of parse: a common, language-neutral, internal representation 12. SHREDDING 13. UPDATEing of queries. 14. >> Four ways to query XML in DB2 15. Plain SQL 16. SQL/XML Traditional, cost based query optimization is performed [based on tra- 17. XQuery ditional stats]! 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store - cost-based access plan generation XML in the database - query rewrite - operator selection - index selection - ... XML Support in DB2 V9 ABIS 43
  • 45. Optimization (ii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces New - XML INDEXes 4. XML-based standards 5. Parsing 6. Transforming 7. Searching CREATE INDEX odindex ON orders(orderinfo) 8. Storing 9. Ubiquitous XML GENERATE KEY USING XMLPATTERN '/order/orderdate' as SQL DATE; 10. >>> XML in DB2 V9 <<< 11. INSERTing XML 12. SHREDDING 13. UPDATEing - specify table name 14. >> Four ways to query XML in DB2 15. Plain SQL - specify column name 16. SQL/XML 17. XQuery - specify XML pattern to be used for identifying target to be in- 18. XQuery with embedded SQL 19. >> Optimization dexed, using XPath notation 20. Epilogue: When to store XML in the database - traditional behaviour Observation: internal indexes are created and maintained by DB2 when using XML data type columns: regions index (data retrieval - one per table) XML column path index (data (subset) retrieval, document indexing - one per XML column) XML Support in DB2 V9 ABIS 44
  • 46. Optimization (iii) XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces RUNSTATS has been enhanced to support XML type columns! 4. XML-based standards 5. Parsing 6. Transforming - collected info 7. Searching 8. Storing · XML document level statistics 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< · XML node level statistics 11. INSERTing XML 12. SHREDDING 13. UPDATEing - collected by means of sampling 14. >> Four ways to query XML in DB2 15. Plain SQL - info gathered: 16. SQL/XML 17. XQuery · Path distribution data [# rows with XPath # occurrences of XPath is 18. XQuery with embedded SQL 19. >> Optimization encountered within each XML] 20. Epilogue: When to store XML in the database · Path-Value distribution data [value of XPath expression, # rows that contain that value, # of value occurrences within each document] - traditional use - when requesting runstats on XML columns only, statistics de- scribing other column data is maintained! XML Support in DB2 V9 ABIS 45
  • 47. Epilogue: When to store XML in the database 20 XML Support in DB2 V9 1. >>> XML basics 2. Defining/imposing document structure 3. Namespaces Hierarchical data 4. XML-based standards 5. Parsing 6. Transforming 7. Searching Semi-structured data 8. Storing 9. Ubiquitous XML 10. >>> XML in DB2 V9 <<< Document/narrative data 11. INSERTing XML 12. SHREDDING 13. UPDATEing 14. >> Four ways to query XML Many different schemas in DB2 15. Plain SQL 16. SQL/XML 17. XQuery Large schemas (with sparsely populated attributes/elements) 18. XQuery with embedded SQL 19. >> Optimization 20. Epilogue: When to store XML in the database Quickly evolving schema Forms-based applications Data with nulls & multiple values Existing industry standard schemas for XML XML Support in DB2 V9 ABIS 46

×