Generating XML from Relational Data ...
Upcoming SlideShare
Loading in...5
×
 

Generating XML from Relational Data ...

on

  • 805 views

 

Statistics

Views

Total Views
805
Views on SlideShare
805
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • We will learn an important new feature in DB2 z/OS v8. DB2 z/OS v8 includes a set of new SQL built-in functions for generating (or publishing) XML from relational data that complies to the SQL/XML standard. SQL/XML will be a new part of the SQL standard, containing XML related specifications for SQL.
  • Unlike DB2 XML extender, this set of functions are SQL built-in functions.
  • Overview chart
  • The first argument of XMLELEMENT is an identifier for the element name, not a literal. There is only specification that maps an SQL identifier to an XML name, not a literal to an XML name. In other context of an SQL query, such an identifier would be treated as a column name. Therefore, the “NAME” keyword is used to differentiate it from a column name. Effort has been made in the implementation to avoid making “NAME” as a reserved word. However, “XMLELEMENT” has to become a reserved word. Therefore, strictly speaking, XMLELEMENT is not a function, but an expression specification. “SYSIBM.” schema prefix cannot be used in front of XMLELEMENT. In addition, XMLATTRIBUTES can only be used as the second argument of XMLELEMENT. AS clause inside XMLATTRIBUTES is necessary since an XML attribute must have a name, which is either derived from a column name, or explicitly specified using the AS clause. In this example, there is no content for the element. In general there can be many arguments as the content of the element, as we will see in the following examples. The current XML functions cannot generate an empty-element tag, such as , according to the SQL/XML standard working draft. The result is in UTF-8, but will be converted into application encoding scheme at bind out.
  • The first argument of XMLELEMENT is an identifier for the element name, not a literal. There is only specification that maps an SQL identifier to an XML name, not a literal to an XML name. In other context of an SQL query, such an identifier would be treated as a column name. Therefore, the “NAME” keyword is used to differentiate it from a column name. Effort has been made in the implementation to avoid making “NAME” as a reserved word. However, “XMLELEMENT” has to become a reserved word. Therefore, strictly speaking, XMLELEMENT is not a function, but an expression specification. “SYSIBM.” schema prefix cannot be used in front of XMLELEMENT. In addition, XMLATTRIBUTES can only be used as the second argument of XMLELEMENT. AS clause inside XMLATTRIBUTES is necessary since an XML attribute must have a name, which is either derived from a column name, or explicitly specified using the AS clause. In this example, there is no content for the element. In general there can be many arguments as the content of the element, as we will see in the following examples. The current XML functions cannot generate an empty-element tag, such as , according to the SQL/XML standard working draft. The result is in UTF-8, but will be converted into application encoding scheme at bind out.
  • This example shows how XML namespaces can be declared using XMLNAMESPACES. This was changed from the earlier standard draft, which allowed XMLATTRIBUTES to declare namespaces (incompatible change). This example also shows one argument for the element content. Note that the generated XML display in this example has been formatted for easy viewing. The real XML generated contains no line breaks.
  • XML functions can be nested to any number of levels.
  • XMLFOREST is used to generate a concatenated list of elements, one for each argument except for the namespace declarations. The elements are of a simple pattern, without attributes. The behavior of XMLFOREST on null values is different from XMLELEMENT. No element is generated for a null value in XMLFOREST, while an empty element is generated if all the arguments (except the first name argument) are null for XMLELEMENT. XMLFOREST is convenient to export a table in XML format, especially when the columns are sparse.
  • Mixed content with text and elements can be generated by XMLELEMENT by supplying mixed arguments. There is no other way to generate mixed content at the present.
  • Because of strong typing, a new concatenation function is introduced. The above example cannot be generated by XMLFOREST. Unlike many traditional functions, which usually return the null on a null argument, arguments with null values will be ignored for XMLCONCAT.
  • XMLAGG is the only XML aggregate function. It concatenates XML values from a group of rows. Right now, no mixed content can be generated from XMLAGG.
  • XMLAGG is also the only aggregate function that allows a new ORDER BY clause inside. DB2 z/OS uses internal quick-sort for the ORDER BY inside XMLAGG. No data is ever moved, thus having very high performance. Please note that ORDER BY sorting is based on the SQL values of the ORDER BY keys. If a key happens to appear in XML also, the result order may not be as expected due to encoding scheme change. For example, a column PRODCODE uses EBCDIC. For two values "P001" and "PA01", relationship "P001" > "PA01" holds in EBCDIC, whereas "P001" < "PA01" is true in Unicde UTF-8. If the same sort key values are used in the XML value expression, use the CAST function to convert the sort key to Unicode to keep the ordering of XML values consistent with that of the sort key.
  • Nesting is very typical in the XML world. This example shows how a nested structure can be generated using XMLAGG and scalar fullselect. Unlike other aggregate functions, XMLAGG does not restrict a scalar fullselect inside its argument. This query asks all the projects under department ‘D01’, and all the employees working for each project. The sample tables shipped with DB2 z/OS v8 are used in this example. You should not be worried about the performance. DB2 z/OS does a good job in reducing data movement for these functions.
  • HTML is a predefined document type of XML. HTML documents can be generated by XML publishing functions. This is an example for an HTML table.
  • This is what the HTML file looks like for the previous screen shot. It contains a single top element TABLE. Its content contains sub-elements CAPTION and table rows TRs. Each table row TR in turn contains table header TH or table data TD.
  • This is the query to generate the HTML file. As we can see from this example, VARCHAR can be used if the XML data is not too long. If a huge XML is generated, a LOB locator has to be used. The resulting CLOB data is only materialized in memory for performance.
  • Just to illustrate how publishing functions can be used to generate some real XML text, such as SOAP messages. But when it gets a little complex, they look quite messy. In this example, I have used literals for illustration, typically columns will be used for contents.
  • Nesting is very typical in the XML world. This example shows how a recursive nested structure can be generated using XMLAGG and scalar fullselect. Recursive XML cannot be easily generated by recursive CTE (Common Table Expression).
  • Nesting is very typical in the XML world. This example shows how a recursive nested structure can be generated using XMLAGG and scalar fullselect. Recursive XML cannot be easily generated by recursive CTE (Common Table Expression).
  • XML names have different rules from SQL identifiers. XML values also have their own format and escaping rules.
  • Something we are working on.

Generating XML from Relational Data ... Generating XML from Relational Data ... Presentation Transcript

  • IBM GLOBAL SERVICES F15 Guogen (Gene) Zhang Generating XML from Relational Data Using SQL with Ease ® Orlando, FL Sept. 12-16, 2005
  • Outline
    • XML basics and motivation for SQL/XML publishing functions
    • XML publishing functions by example
    • Advanced topics
    • Preview of future SQL/XML features
    • Summary
  • XML Basics I <Emp name=&quot;Jack Lee&quot;> <BIRTHDAY>1960-10-28</BIRTHDAY> <department>Shipping</department> </Emp> Element name Attribute name Attribute value Start tag End tag Element content for “department” } Nested elements as content of “Emp”
  • XML Basics II <hr:Emp xmlns:hr=&quot; http:// www.example.com/hr.xsd &quot; name=&quot;Jack Lee&quot;> <hr:BIRTHDAY>1960-10-28</hr:BIRTHDAY> <hr:department>Shipping</hr:department> </hr:Emp> Prefix Namespace prefix Namespace name (URI) QName Local part Namespace declaration NCName
  • Motivation for XML Publishing Functions
    • The world wants XML.
    • Majority of DB2 data is still relational.
    • Generating XML from relational data makes DB2 an XML data source.
    • That's what XML constructor functions are for.
    • And that is the first step towards total XML support inside engine.
  • Advantages of using SQL/XML Functions
    • Easy to extend existing applications with XML using SQL
      • Works for non-Unicode tables
    • Lightweight Web server/applications
      • Submit SQL queries and return results to Web/XML clients
    • Less application development efforts
    • High-performance
      • Better performance for tables in Unicode
    • Conforming to the SQL/XML standard
  • XML Publishing Functions
    • Scalar functions (constructors)
      • XMLELEMENT, XMLATTRIBUTES
      • XMLNAMESPACES (DB2 LUW V8.2)
      • XMLFOREST
      • XMLCONCAT
    • Aggregate function: XMLAGG
    • Transient XML data type – internal use only
    • Cast function: XML2CLOB (DB2 LUW 8.2: XMLSERIALIZE)
    • Available in DB2 V8 (z/OS New Function Mode)
  • XML Functions by Example – 1. simple element <Emp>Jack Lee</Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot; Emp &quot; , e.fname ||' '|| e.lname ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 1’. simple element <Emp name=&quot;Jack Lee&quot;></Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot; Emp &quot; , XMLATTRIBUTES(e.fname ||' '|| e.lname AS &quot;name&quot;) ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example - 1’. simple element null values <Emp></Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot; Emp &quot; , XMLATTRIBUTES(e.fname ||' '|| e.lname AS &quot;name&quot;) ) ) AS &quot;result&quot; FROM employees e WHERE ...; Use CASE expression to avoid empty elements
  • XML Functions by Example – 2. namespace <doc:Emp xmlns:doc=&quot;http://www.ibm.com/emp.xsd&quot; > Jack Lee </doc:Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot;doc:Emp&quot;, XMLNAMESPACES ('http://www.ibm.com/emp.xsd ' AS &quot;doc&quot; ), e.fname ||' '|| e.lname) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 2’ namespace - illegal <doc:Emp xmlns:doc=&quot;http://www.ibm.com/emp.xsd&quot; > Jack Lee </doc:Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot;doc:Emp&quot;, XMLATTRIBUTES ('http://www.ibm.com/emp.xsd ' AS &quot;xmlns:doc&quot; ), e.fname ||' '|| e.lname) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 3. nested elements <Emp name=&quot;Jack Lee&quot;> <BIRTHDAY>1960-10-28</BIRTHDAY> <department>Shipping</department> </Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot;Emp&quot;, XMLATTRIBUTES(e.fname ||' '|| e.lname AS &quot;name&quot;) XMLELEMENT(NAME BIRTHDAY, e.birthday), XMLELEMENT(NAME “department”, e.dept) ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 3’. alternative <Emp name=&quot;Jack Lee&quot;> <BIRTHDAY>1960-10-28</BIRTHDAY> <department>Shipping</department> </Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot;Emp&quot;, XMLATTRIBUTES(e.fname ||' '|| e.lname AS &quot;name&quot;) XMLFOREST(e.birthday, e.dept as “department”) ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 4. mixed content <Emp>Employee <name>Jack Lee</name> was hired on <hiredate>2000-05-24</hiredate> </Emp> SELECT XML2CLOB( XMLELEMENT(NAME &quot;Emp&quot;, ‘ Employee ’, XMLELEMENT(NAME “name”, e.fname ||' '|| e.lname), ‘ was hired on ’, XMLELEMENT(NAME “hiredate”, e.hire) ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 5. concat <Emp name=&quot;Jack Lee&quot;></Emp> <department>Shipping</department> SELECT XML2CLOB( XMLCONCAT ( XMLELEMENT(NAME &quot;Emp&quot;, XMLATTRIBUTES(e.fname ||' '|| e.lname AS &quot;name&quot;) ), XMLELEMENT(NAME “department”, e.dept) ) ) AS &quot;result&quot; FROM employees e WHERE ...;
  • XML Functions by Example – 6. grouping <Department name=&quot;Shipping&quot;> <emp>Oppenheimer</emp> <emp>Martin</emp> <emp>Lee</emp> </Department> SELECT XML2CLOB( XMLELEMENT(NAME &quot;Department&quot;, XMLATTRIBUTES (e.dept AS &quot;name&quot; ), XMLAGG(XMLELEMENT(NAME &quot;emp&quot;, e.lname) ) ) ) AS &quot;dept_list&quot; FROM employees e GROUP BY dept;
  • XML Functions by Example – 6’. grouping with order <Department name=&quot;Shipping&quot;> <emp>Lee</emp> <emp>Martin</emp> <emp>Oppenheimer</emp> </Department> SELECT XML2CLOB( XMLELEMENT(NAME &quot;Department&quot;, XMLATTRIBUTES (e.dept AS &quot;name&quot; ), XMLAGG(XMLELEMENT(NAME &quot;emp&quot;, e.lname) ORDER BY e.lname ) ) ) AS &quot;dept_list&quot; FROM employees e GROUP BY dept;
  • XML Functions by Example – 7. complex query SELECT XML2CLOB( XMLELEMENT( NAME &quot;Dept&quot;, XMLATTRIBUTES ( D.DEPTNO AS &quot;deptno&quot;, D.DEPTNAME AS &quot;name&quot; ), ( SELECT XMLAGG ( XMLELEMENT (NAME &quot;Proj&quot;, XMLATTRIBUTES (P.PROJNO AS &quot;projno&quot;, P.PROJNAME AS &quot;name&quot;), ( SELECT XMLAGG ( XMLELEMENT (NAME &quot;Emp&quot;, XMLATTRIBUTES(E.EMPNO as &quot;empno&quot;), E.FIRSTNME || ' ' || E.LASTNAME ) ) FROM DSN8810.EMPPROJACT EP, DSN8810.EMP E WHERE EP.PROJNO = P.PROJNO AND EP.EMPNO = E.EMPNO ) ) ) FROM DSN8810.PROJ P WHERE P.DEPTNO = D.DEPTNO ) ) ) FROM DSN8810.DEPT D WHERE D.DEPTNO = 'D01';
  • XML Functions by Example – 7. result <Dept deptno=&quot;D01&quot; name=&quot;DEVELOPMENT CENTER&quot;> <Proj projno=&quot;AD3100&quot; name=&quot;ADMIN SERVICES&quot;> <Emp empno=&quot;000010&quot;>CHRISTINE HAAS</Emp> </Proj> <Proj projno=&quot;MA2100&quot; name=&quot;WELD LINE AUTOMATION&quot;> <Emp empno=&quot;000010&quot;>CHRISTINE HAAS</Emp> <Emp empno=&quot;000110&quot;>VINCENZO LUCCHESI</Emp> </Proj> </Dept>
  • XML Functions by Example – 8. HTML table
  • XML Functions by Example – 8. HTML file <TABLE border=&quot;1&quot;><CAPTION>Department-Employee Table</CAPTION> <TR><TH>Dept No</TH><TH>Dept Name</TH><TH>Emp No</TH> <TH>Emp Name</TH><TH>Phone</TH></TR> <TR><TD rowspan=&quot;6&quot;>A00</TD> <TD rowspan=&quot;6&quot;>SPIFFY COMPUTER SERVICE DIV.</TD></TR> <TR><TD>000010</TD><TD>CHRISTINE HAAS</TD><TD>3978</TD></TR> <TR><TD>000110</TD><TD>VINCENZO LUCCHESI</TD><TD>3490</TD></TR> <TR><TD>000120</TD><TD>SEAN O'CONNELL</TD><TD>2167</TD></TR> <TR><TD>200010</TD><TD>DIAN HEMMINGER</TD><TD>3978</TD></TR> <TR><TD>200120</TD><TD>GREG ORLANDO</TD><TD>2167</TD></TR> <TR><TD rowspan=&quot;5&quot;>C01</TD> <TD rowspan=&quot;5&quot;>INFORMATION CENTER</TD></TR> <TR><TD>000030</TD><TD>SALLY KWAN</TD><TD>4738</TD></TR> <TR><TD>000130</TD><TD>DOLORES QUINTANA</TD><TD>4578</TD></TR> <TR><TD>000140</TD><TD>HEATHER NICHOLLS</TD><TD>1793</TD></TR> <TR><TD>200140</TD><TD>KIM NATZ</TD><TD>1793</TD></TR> </TABLE>
  • XML Functions by example – 8. the query for HTML table SELECT VARCHAR( XML2CLOB( XMLElement(NAME &quot;TABLE&quot;, XMLATTRIBUTES('1' as &quot;border&quot;), XMLElement(NAME CAPTION , 'Department-Employee Table'), XMLElement(NAME TR, XMLFOREST('Dept No‘ as TH, 'Dept Name‘ as TH, 'Emp No‘ as TH, 'Emp Name‘ as TH, 'Phone‘ as TH) ), XMLAGG( XMLCONCAT( XMLELEMENT(NAME TR, XMLELEMENT(NAME TD, XMLATTRIBUTES( X.CNT+1 as &quot;rowspan&quot;), D.DEPTNO), XMLELEMENT(NAME TD, XMLATTRIBUTES( X.CNT+1 as &quot;rowspan&quot;), D.DEPTNAME) ), ( SELECT XMLAGG(XMLElement(NAME TR, XMLForest(EMPNO as TD, FIRSTNME || ' ' || LASTNAME as TD, PHONENO as TD) ) ) FROM DSN8810.EMP E WHERE E.WORKDEPT = D.DEPTNO ) ) ) ) ) ) FROM DSN8810.DEPT D, (SELECT WORKDEPT, COUNT(*) FROM DSN8810.EMP GROUP BY WORKDEPT) X(DEPTNO, CNT) WHERE D.DEPTNO = X.DEPTNO AND D.DEPTNO IN ('A00', 'C01'); } } Table Header Dept } Emp
  • XML Functions by Example -- 9 SOAP message with empty body <env:Envelope xmlns:env=&quot;http://www.w3.org/2002/12/soap-envelope&quot;> <env:Header> <m:reservation xmlns:m= “ http:// travelcompany.example.org /reservation ” env:role=“ http://www.w3.org/2002/12/soap-envelope/role/next ” env:mustUnderstand=&quot;true&quot;> <m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</m:reference> <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> </m:reservation> <n:passenger xmlns:n=“ http:// mycompany.example.com /employees ” env:role=“ http://www.w3.org/2002/12/soap-envelope/role/next ” env:mustUnderstand=&quot;true&quot;> <n:name>Jack Lee</n:name> </n:passenger> </env:Header> <env:Body>… </env:Body> </env:Envelope>
  • XML Functions by Example - 9 code for SOAP msg w/ empty body XMLELEMENT(NAME “env:Envelope”, XMLNAMESPACES(‘http://www.w3.org/2002/12/soap-envelope’ AS “env”), XMLELEMENT(NAME “env:Header”, XMLELEMENT(NAME “m:reservation”, XMLNAMESPACES(‘ http://travelcompany.example.org/reservation ’ AS “m”, ‘ http://www.w3.org/2002/12/soap-envelope/role/next ’ AS “role”), XMLATTRIBUTES(‘true’ AS “env:mustUnderstand”), XMLELEMENT(NAME “m:reference”, ‘uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d’), XMLELEMENT(NAME “m:dateAndTime”, ‘2001-11-29T13:20:00.000-05:00’) ), XMLELEMENT(NAME “n:passenger”, XMLNAMESPACES( ‘ http:// mycompany.example.com /employees ’ AS “n”, ‘ http://www.w3.org/2002/12/soap-envelope/role/next ’ AS “role”), XMLATTRIBUTES(‘true’ AS “env:mustUnderstand”), XMLELEMENT(NAME “n:name”, ‘Jack Lee’) ) ), XMLELEMENT(NAME “env:Body”, ‘…’) )
  • XML Functions by Example – 10. recursive document Base: One level – no recursion SELECT XML2CLOB(XMLELEMENT(NAME &quot;PartList&quot;, XMLAGG(XMLELEMENT(NAME &quot;Part&quot;, XMLATTRIBUTES(P.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, P.PartName) ) ORDER BY P.PartID ) ) ) FROM Part P WHERE P.ParentPartID = 0; Base: One level – no recursion Part (PartID, PartName, ParentPartID) <PartList> <Part PartID=“1”> <PartName>Car</PartName> </Part> </PartList>
  • XML Functions by Example – 10. recursive document SELECT XML2CLOB(XMLELEMENT(NAME &quot;PartList&quot;, XMLAGG(XMLELEMENT(NAME &quot;Part&quot;, XMLATTRIBUTES(P.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, P.PartName) , (SELECT XMLAGG(XMLELEMENT(NAME &quot;Part &quot;, XMLATTRIBUTES(S.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, S.PartName) ) ORDER BY S.PartID ) FROM Part S WHERE S.ParentPartID = P.PartID ) ) ORDER BY P.PartID) ) ) FROM Part P WHERE P.ParentPartID = 0; Two level recursion: <PartList> <Part PartID=“1”> <PartName>Car</PartName> <Part PartID=“2”> <PartName>Body</PartName> </Part> … </Part> </PartList>
  • XML Functions by Example – 10. recursive document Three level recursion: SELECT XML2CLOB(XMLELEMENT(NAME &quot;PartList&quot;, XMLAGG(XMLELEMENT(NAME &quot;Part&quot;, XMLATTRIBUTES(P.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, P.PartName) , (SELECT XMLAGG(XMLELEMENT(NAME &quot;Part &quot;, XMLATTRIBUTES(S.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, S.PartName) , (SELECT XMLAGG(XMLELEMENT(NAME &quot;Part&quot;, XMLATTRIBUTES(SS.PartID as &quot;PartID&quot;), XMLELEMENT(NAME &quot;PartName&quot;, SS.PartName) ) ORDER BY SS.PartID ) FROM Part SS WHERE SS.ParentPartID = S.PartID ) ) ORDER BY S.PartID ) FROM Part S WHERE S.ParentPartID = P.PartID ) ) ORDER BY P.PartID) ) ) FROM Part P WHERE P.ParentPartID = 0; Three level recursion:
  • XML Functions by Example – 10. recursive document sample result <PartList> <Part PartID=“1”> <PartName>Car</PartName> <Part PartID=“2”> <PartName>Body</PartName> <Part PartID=“3”> <PartName>Frame</PartName> </Part> <Part PartID=“4”> <PartName>Doors</PartName> </Part> </Part> <Part PartID=“5”> <PartName>Wheels</PartName> </Part> </Part> </PartList> Three level recursion:
  • SQL to XML Mappings
    • SQL <identifier>s to XML names
      • Escaping for column names
      • SQL: &quot;Order Items&quot; => XML: &quot;Order_x0020_Items&quot;
      • SQL: &quot;XMLDoc&quot; => XML: &quot;_x0078_MLDoc&quot;
      • SQL: &quot;dept:id&quot; => XML: &quot;dept_x003A_id“
    • SQL values to XML values
      • SQL: 'Shipping & Receiving’ => XML: 'Shipping &amp; Receiving'
      • SQL: 'X < 5' => XML: 'X &lt; 5'
      • SQL: '2002-02-26-10.01.01.123456'
    • => XML: '2002-02-26T10:01:01.123456'
  • XML Functions in Views
    • Need to use XML2CLOB
    • Using CLOB result for XML in other XML constructors will lead to surprising result.
    • “ <Emp>Jack Lee</Emp>” will be become “&lt;Emp&gt;Jack Lee&lt;/Emp&gt;” if it’s used in XMLELEMENT as content.
  • Namespace Scoping
    • Namespaces declared by XMLNAMESPACES are syntactically scoped within the XMLELEMENT/XMLFOREST function, e.g. XMLELEMENT (…, NAMESPACES(…as “ns”) …).
    • Namespace prefixes need to be declared in-scope except for these pre-defined namespace prefixes: xml, xs, xsd, xsi, sqlxml
    start end
  • Major Optimization Techniques (DB2 z/OS)
    • Flatten nested XML scalar functions into one function and a tagging template - avoid data copy
    • Two phase processing for XML:
      • Map SQL values to XML values and build in-memory records before tagging
      • Apply tagging templates to generate XML string (Serialize)
    • Materialized XML values in workfile contains only the handles to XML values in memory
    • Optimize XMLAGG by internal quicksort for ORDER BY, and sharing tagging template for its argument
    • Serialized XML text has no superfluous namespace declarations
    • XML2CLOB materializes CLOB in-memory only.
  • Composition by DB2 SQL/XML Publishing functions in V8
      • Z990 5 processors, 10GB,
      • z/OS 1.4,
      • DB2 for z/OS V8
  • Composition: XML Extender v.s. Publishing V8 XML Extender for DB2 for z/OS V8 IXM4C40 IXMLC13
  • Preview of Future SQL/XML Features DB2 Engine 2 1 3 4 5 6 7 8 9 Application Textual XML Relational XML 1 2 3 4 5 6 7 8 9 Bind in XML Store as XML Shred into SQL Retrieve XML Publish XML Bind out XML XML to XML XML to SQL SQL to XML 0 Data model
  • Summary
    • SQL/XML publishing functions in DB2 V8
    • Performance characteristics (z/OS)
    • Preview of some future SQL/XML features
  • Thanks!
    • Guogen (Gene) Zhang, gzhang@us.ibm.com