<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Native XML Database</title>
	<atom:link href="http://nativexmldatabase.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nativexmldatabase.com</link>
	<description></description>
	<lastBuildDate>Thu, 09 Feb 2012 00:46:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nativexmldatabase.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Native XML Database</title>
		<link>http://nativexmldatabase.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nativexmldatabase.com/osd.xml" title="Native XML Database" />
	<atom:link rel='hub' href='http://nativexmldatabase.com/?pushpress=hub'/>
		<item>
		<title>How to list the paths of all elements in an XML document?</title>
		<link>http://nativexmldatabase.com/2012/02/04/how-to-list-the-paths-of-all-elements-in-an-xml-document/</link>
		<comments>http://nativexmldatabase.com/2012/02/04/how-to-list-the-paths-of-all-elements-in-an-xml-document/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 21:35:32 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1408</guid>
		<description><![CDATA[A common question is how to obtain a list of all the elements and attributes that occur in an XML document. Producing such a list is what I call &#8220;XML profiling&#8221; and in a previous blog post I have discussed several SQL/XML queries that can do this. An extension of this question is how to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1408&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A common question is how to obtain a list of all the elements and attributes that occur in an XML document. Producing such a list is what I call &#8220;XML profiling&#8221; and in a <a href="http://nativexmldatabase.com/2010/05/26/xml-profiling-how-to-get-a-list-of-all-elements-and-attributes/">previous blog post</a> I have discussed several SQL/XML queries that can do this.</p>
<p>An extension of this question is how to get the paths of all the elements and attributes in a document. This seemingly simple task is -unfortunately- not nearly as simple as one would think! XPath and XQuery do not have a function that takes a given element or attribute as input and returns the full path to that node.</p>
<p>The solution is to write a query that traverses the XML document level by level to collect the element names at every level and concatenate them appropriately to construct the paths for every elements and attributes at every level.</p>
<p>There are many ways in which this can be done. You can use XQuery or SQL/XML and you can choose whether to use recursion or not. Let&#8217;s look at a few examples.</p>
<p>First, let&#8217;s create a simple table with a small document that we can use in the examples:</p>
<p><pre class="brush: sql;">
create table mytable(xmldoc XML);

insert into mytable values(
'&lt;Message&gt;
   &lt;Type&gt;Urgent&lt;/Type&gt;
   &lt;Person id =&quot;123&quot;&gt;
     &lt;FirstName&gt;Robert&lt;/FirstName&gt;
     &lt;LastName&gt;Tester&lt;/LastName&gt;
   &lt;/Person&gt;
 &lt;/Message&gt;');
</pre></p>
<p>A first and straightforward solution is to start at the root of the document, then at the first level of child nodes, and then at the children of each these child nodes, and so on. For each element or attribute we construct the path by concatenating the path from the parent with the name of the element or attribute. We do this for all nodes at a given level in the tree and then move to the next level of the document.:</p>
<p><pre class="brush: sql;">
xquery
for $L1 in db2-fn:xmlcolumn(&quot;MYTABLE.XMLDOC&quot;)/*
let $L1path := fn:string-join( ($L1/local-name() ),&quot;/&quot; )
return (
  $L1path,
  for $L2 in $L1/(*,@*)
  let $L2path := fn:string-join( ($L1path, $L2/local-name() ),&quot;/&quot; )
  return (
    $L2path,
    for $L3 in $L2/(*,@*)
    let $L3path := fn:string-join( ($L2path, $L3/local-name() ),&quot;/&quot; )
    return (

    $L3path,
    for $L4 in $L3/(*,@*)
    let $L4path := fn:string-join( ($L3path, $L4/local-name() ),&quot;/&quot; )
    return (

    $L4path,
    for $L5 in $L4/(*,@*)
    let $L5path := fn:string-join( ($L4path, $L5/local-name() ),&quot;/&quot; )
    return ($L5path)))));

Message
Message/Type
Message/Person
Message/Person/id
Message/Person/FirstName
Message/Person/LastName

6 record(s) selected.
</pre></p>
<p>The obvious shortcoming of this query is that it assumes a maximum of 5 levels in the document. If your documents are deeper than this, you can easily extend the query so that it goes down to 10 or 20 levels, whatever you need. That&#8217;s maybe not very elegant, but it works if you can define an upper bound on the depths of your XML documents, which is usually possible.</p>
<p>You probably notice that the path <strong>Message/Person/id</strong> should actually be <strong>Message/Person/@id</strong> because &#8220;id&#8221; is an XML attribute. The query can enhanced to take care of such details. In the last two sample queries of my <a href="http://nativexmldatabase.com/2010/05/26/xml-profiling-how-to-get-a-list-of-all-elements-and-attributes/">XML profiling post</a> you have seen how to use the <code>self::attribute()</code> test for this purpose.</p>
<p>If you prefer a more elegant solution that does not require any assumption about the maximum depths of the XML documents, then you need to code a recursive query, either in XQuery or in SQL/XML. Let&#8217;s try SQL/XML for a change.</p>
<p>You may already be familiar with how recursive SQL works. If not, you can look at <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000879.html">several existing examples</a>. The basic idea is to use a WITH clause, also called &#8220;common table expression&#8221;, that contains a UNION ALL between the start of the processing and a recursive reference back to the common table expression itself. The following  augments this approach with the XMLTABLE function that extracts nodes and node names from the XML:</p>
<p><pre class="brush: sql;">
WITH pathstable (name, node, xpath) AS (
  SELECT x.name AS name, x.node AS xmlnode,'/' || x.name AS xpath
  FROM mytable,
       XMLTABLE('$XMLDOC/*'
        COLUMNS
          name    varchar(30) PATH './local-name()',
          node    XML         PATH '.') AS x
  UNION ALL
  SELECT y.name AS name, y.node AS xmlnode, xpath|| '/' || y.name AS xpath
  FROM pathstable,
       XMLTABLE('$XMLNODE/(*,@*)' PASSING pathstable.node AS &quot;XMLNODE&quot;
        COLUMNS
         name    varchar(30) PATH 'local-name()',
         node    XML         PATH '.') AS y
) SELECT name, xpath
  FROM pathstable;

NAME                           XPATH
------------------------------ -------------------------------
Message                        /Message
Type                           /Message/Type
Person                         /Message/Person
id                             /Message/Person/id
FirstName                      /Message/Person/FirstName
LastName                       /Message/Person/LastName

6 record(s) selected
</pre></p>
<p>If you want to list the element and attribute values for each path, then you can easily modify this query as follows:</p>
<p><pre class="brush: sql;">
WITH pathstable (name, node, xpath, value) AS (
  SELECT x.name AS name, x.node AS xmlnode,
         '/' || x.name AS xpath, x.value as value
  FROM mytable,
       XMLTABLE('$XMLDOC/*'
        COLUMNS
          name    varchar(30) PATH './local-name()',
          value   varchar(20) PATH 'xs:string(.)',
          xmlnode XML         PATH '.') AS x
  UNION ALL
  SELECT y.name AS name, y.node AS xmlnode,
         xpath|| '/' || y.name AS xpath, y.value as value
  FROM pathstable,
       XMLTABLE('$XMLNODE/(*,@*)' PASSING pathstable.node AS &quot;XMLNODE&quot;
        COLUMNS
          name    varchar(30) PATH 'local-name()',
          value   varchar(20) PATH 'xs:string(.)',
          xmlnode XML         PATH '.') AS y
) SELECT xpath, value
  FROM pathstable;

XPATH                           VALUE
------------------------------- --------------------
/Message                        UrgentRobertTester
/Message/Type                   Urgent
/Message/Person                 RobertTester
/Message/Person/id              123
/Message/Person/FirstName       Robert
/Message/Person/LastName        Tester

6 record(s) selected
</pre></p>
<p>A few things to note:</p>
<ul>
<li>The value of an XML element is defined at the concatenation of all text nodes in the subtree under that element. This explains the values that you see for /Message and /Message/Person in the example above.</li>
<li>For longer paths you may need to increase the length of the VARCHAR(n) in the XMLTABLE function.</li>
<li>In DB2 you may receive warning SQL0347W, which says that this query might recursively run into an infinite loop. But, this would only happen if your XML document was infinitely deep, which isn&#8217;t possible. So, you can safely ignore that warning.</li>
</ul>
<p>&nbsp;</p>
<pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1408/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1408&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2012/02/04/how-to-list-the-paths-of-all-elements-in-an-xml-document/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>Business Records in the 21st Century</title>
		<link>http://nativexmldatabase.com/2012/01/21/business-records-in-the-21st-century/</link>
		<comments>http://nativexmldatabase.com/2012/01/21/business-records-in-the-21st-century/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 16:46:08 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1402</guid>
		<description><![CDATA[Part 2 of our article &#8220;Data normalization reconsidered&#8221; is now available at http://www.ibm.com/developerworks/data/library/techarticle/dm-1201normalizationpart2/index.html The second part discusses alternatives to a traditional normalized relational representation of data. Such alternatives include for example XML, JSON, and RDF because they can often help you overcome normalization issues or improve schema flexibility, or both. In the 21st century, digitized [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1402&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Part 2 of our article &#8220;Data normalization reconsidered&#8221; is now available at</p>
<p><a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-1201normalizationpart2/index.html">http://www.ibm.com/developerworks/data/library/techarticle/dm-1201normalizationpart2/index.html</a></p>
<p>The second part discusses alternatives to a traditional normalized relational representation of data. Such alternatives include for example XML, JSON, and RDF because they can often help you overcome normalization issues or improve schema flexibility, or both. In the 21st century, digitized business records are often created in XML to begin with, which makes XML an attractive choice as the database level storage format.</p>
<p>This article also contains a performance comparison between XML and relational data that was conducted for a real-world application scenario at a major international logistics company.</p>
<p>At the end of the article you find comparison tables that summarize the pros and cons of different data representations.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1402/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1402&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2012/01/21/business-records-in-the-21st-century/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>Data Normalization Reconsidered</title>
		<link>http://nativexmldatabase.com/2012/01/08/data-normalization-reconsidered/</link>
		<comments>http://nativexmldatabase.com/2012/01/08/data-normalization-reconsidered/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 03:52:21 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1396</guid>
		<description><![CDATA[Normalization is a design methodology for relational database schemas and aims to minimize data redundancy and avoid data anomalies, such as update anomalies. The consequence of normalization is that business records (such as a purchase order, an insurance claim, a financial transaction, etc.) are split into pieces that are scattered over potentially many relational tables. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1396&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Normalization is a design methodology for relational database schemas and aims to minimize data redundancy and avoid data anomalies, such as update anomalies. The consequence of normalization is that business records (such as a purchase order, an insurance claim, a financial transaction, etc.) are split into pieces that are scattered over potentially many relational tables.</p>
<p>In addition to its benefits, normalization also introduces several drawbacks:</p>
<ul>
<li>The insert of a single logical business record requires the insertion of multiple (often many) physical rows</li>
<li>The retrieval of a single business record requires complex multi-way joins or a series of separate queries</li>
<li>Business records undergo a potentially expensive conversion from their original representation outside the database to a normalized format and back</li>
<li>The normalized representation of business records is often difficult to understand because it is very different from the original format of the business record, such as a paper form or an XML message.</li>
</ul>
<p>These issues raise the question whether normalization should be applied as categorically as some people believe. Indeed, there are several reasons for reconsidering normalization, such as:</p>
<ul>
<li>Throughout history, humans have always stored their business records &#8220;intact&#8221;, and it was only the introduction of databases that has &#8220;required&#8221; normalization</li>
<li>Normalization was introduced when storage space was extremely scarce and expensive, which is not (or much less) the case anymore today</li>
<li>Today, business records are often much more complex than they used to be in the 1970s when normalization was introduced, and this complexity amplifies the disadvantages of normalization</li>
<li>De-normalization is becoming more and more popular, e.g. in star schemas for data warehousing, but also in emerging storage systems such as HBase, Google&#8217;s BigTable, etc.</li>
</ul>
<p>Today, business records are often created and exchanged in a digital format, and this format is often XML. XML is a non-normalized data format that can provide several benefits:</p>
<ul>
<li>A single business record often maps naturally to a single XML document</li>
<li>A single business record/XML document can be inserted (and retrieved) in an XML database as a single operation</li>
<li>If you store XML as XML (i.e. without conversion to relational), the representation of a business record is the same inside and outside the database, which is tremendously valuable</li>
</ul>
<p>When business records already exist in XML format outside the database anyway, then it is usually best to also store them as XML and not to convert into a normalized relational schema.</p>
<p>My colleague Susan Malaika and I have collected our thoughts and observations on normalization in a 2-part article titled &#8220;<a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-1112normalization/index.html"><strong>Data Normalization Reconsidered</strong></a>&#8220;. The first part has recently been published on developerWorks and can be found here:</p>
<p><a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-1112normalization/index.html">http://www.ibm.com/developerworks/data/library/techarticle/dm-1112normalization/index.html</a></p>
<p>The 2nd part will appear soon. Happy reading!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1396/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1396&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2012/01/08/data-normalization-reconsidered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>XQuery support in DB2 10 for z/OS</title>
		<link>http://nativexmldatabase.com/2011/11/30/xquery-support-in-db2-10-for-zos/</link>
		<comments>http://nativexmldatabase.com/2011/11/30/xquery-support-in-db2-10-for-zos/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 06:13:58 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1374</guid>
		<description><![CDATA[If you think that mainframe computers are old dinosaurs that only run ancient COBOL code &#8211; think again! Now mainframes also run XQuery! While DB2 for Linux, UNIX, and Windows has been supporting XQuery and SQL/XML since Version 9.1 (released in 2006), DB2 9 for z/OS &#8220;only&#8221; supported XPath and SQL/XML. I have put the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1374&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you think that mainframe computers are old dinosaurs that only run ancient COBOL code &#8211; think again! Now mainframes also run XQuery!</p>
<p>While <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.xml.doc/doc/xqrcontainer.html">DB2 for Linux, UNIX, and Windows</a> has been supporting XQuery and <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.xml.doc/doc/c0023896.html">SQL/XML</a> since Version 9.1 (released in 2006), DB2 9 for z/OS &#8220;only&#8221; supported XPath and SQL/XML.</p>
<p>I have put the word &#8220;only&#8221; in quotes because for many applications XPath and SQL/XML are fully sufficient. When you combine XPath expressions with SQL/XML functions such as <a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/">XMLTABLE</a> plus other SQL language constructs you can write <em>very</em> powerful XML queries and accomplish many of the same things that you can do with XQuery.</p>
<p>DB2 10 for z/OS has added a variety of <a href="http://nativexmldatabase.com/2010/11/18/new-xml-features-in-db2-10-for-zos/">new XML features</a> such as node-level XML updates, XML-type parameters and variables in stored procedures and user-defined functions, and enhancements for XML Schemas and XML indexes.</p>
<p>With APARs PM47617 and PM47618, DB2 for z/OS now also supports XQuery within the SQL functions XMLTABLE, XMLQUERY, XMLEXISTS, and XMLMODIFY.</p>
<p>So what are the additional capabilities and benefits that XQuery provides? Examples include:</p>
<ul>
<li>You can compose new XML structures using direct element constructors</li>
<li>You can use FLWOR expressions (for-let-where-order by-return) to iterate over and manipulate intermediate query results</li>
<li>You can join and combine information from multiple XML documents</li>
<li>You can use XQuery comma-expressions to construct and use new sequences of XML nodes</li>
<li>You can code if-then-else logic to implement conditional expressions</li>
<li>etc.</li>
</ul>
<p>Let&#8217;s look at some examples.</p>
<p><strong>Construct new XML structures with direct element and attribute constructors</strong></p>
<p>The following query constructs a new order summary document from each order (XML document) that is selected from the &#8220;orders&#8221; table. New elements, such as &lt;orderSummary&gt; and &lt;orderedItems&gt; are constructed by providing the start and end tags explicitly. Similarly, the attribute orderNumber is also constructed explicitly. The content of the constructed elements and attributes is computed by XPath (or XQuery) expressions that extract selected information from each source document.</p>
<p><pre class="brush: sql;">
SELECT XMLQUERY('
          &lt;orderSummary orderNumber=&quot;{$po/order/orderNo/text()}&quot;&gt;
             &lt;orderedItems&gt;{$o/order/items/item/itemName}&lt;/orderedItems&gt;
          &lt;/orderSummary&gt;'
       PASSING orders.orderdoc AS &quot;po&quot;)
FROM orders
WHERE ...
</pre></p>
<p><strong>FLWOR expressions</strong></p>
<p>The next query joins the tables &#8220;orders&#8221; and &#8220;items&#8221; on their XML columns &#8220;orderdoc&#8221; and &#8220;details&#8221;, respectively. The join predicate in the XMLEXISTS ensures that we find the items that match a given order and that we don&#8217;t produce a Cartesian product. For each pair of order document and item document, the FLWOR expression in the SELECT clause combines information from both documents into a new documents that contains the item name, the ordered quantity, and the item details.</p>
<p><pre class="brush: sql;">
SELECT XMLQUERY('for $o in $po/orders/items/item
                   for $i in $it/item
                 where $o/itemName = $i/name
                 return &lt;orderdItem&gt;
                           {$i/name}
                           {$o/item/quantity}
                           {$i/details}
                        &lt;/orderdItem&gt;'
         PASSING orders.orderdoc AS &quot;po&quot;, items.details as &quot;it&quot;)
FROM orders, items
WHERE
XMLEXISTS('$po/order/items/item[itemName = $it/item/name]'
           PASSING orders.orderdoc AS &quot;po&quot;, items.details as &quot;it&quot;)
</pre></p>
<p>&nbsp;</p>
<p>For more information on XQuery in DB2 10 for z/OS, here is a good place to continue reading:</p>
<p><a href="http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z10.doc.xml/src/tpc/db2z_expover.htm">http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2z10.doc.xml/src/tpc/db2z_expover.htm</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1374/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1374/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1374/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1374&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/11/30/xquery-support-in-db2-10-for-zos/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>TPoX 2.1 has been released!</title>
		<link>http://nativexmldatabase.com/2011/11/15/tpox-2-1-has-been-released/</link>
		<comments>http://nativexmldatabase.com/2011/11/15/tpox-2-1-has-been-released/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 02:57:44 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1358</guid>
		<description><![CDATA[First, what is TPoX?  I have two answers to that question. Answer 1: TPoX, short for &#8220;Transaction Processing over XML&#8221;, is an XML database benchmark that executes and measures a multi-user XML workload. The workload contains XML queries (70%) as well as XML insert, update, and delete operations (30%). TPoX simulates a simple financial application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1358&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First, what is TPoX?  I have two answers to that question.</p>
<p><span style="text-decoration:underline;"><strong>Answer 1:</strong></span></p>
<p><a href="http://tpox.sourceforge.net/">TPoX</a>, short for &#8220;Transaction Processing over XML&#8221;, is an XML database benchmark that executes and measures a multi-user XML workload. The workload contains XML queries (70%) as well as XML insert, update, and delete operations (30%). TPoX simulates a simple financial application that issues XQuery or SQL/XML transactions to stress XML storage, XML indexing, XML Schema support, XML updates, logging, concurrency and other components of an XML database system.</p>
<p>The <a href="http://sourceforge.net/projects/tpox/files/tpox/v2.1/">TPoX package</a> contains:</p>
<ul>
<li>an <a href="http://tpox.svn.sourceforge.net/viewvc/*checkout*/tpox/TPoX/documentation/TPoX_DataGeneration_v2.1.pdf">XML data generator</a></li>
<li>an extensible <a href="http://tpox.svn.sourceforge.net/viewvc/tpox/TPoX21/documentation/WorkloadDriverUsage_v2.1.pdf">Workload Driver</a>, written in Java</li>
<li>three <a href="http://tpox.sourceforge.net/tpoxdata.htm">XML Schemas</a> that define the XML structures</li>
<li>a set of <a href="http://tpox.svn.sourceforge.net/viewvc/*checkout*/tpox/TPoX/documentation/TPoX_BenchmarkProposal_v2.1.pdf">predefined transactions</a>, which can be changed easily</li>
</ul>
<p>TPoX has been developed by Intel and IBM, but is freely available and <a href="http://sourceforge.net/projects/tpox/">open source</a> since 2007. A variety of TPoX <a href="http://tpox.sourceforge.net/tpoxresults.htm">performance results</a> and <a href="http://tpox.sourceforge.net/tpoxresults.htm#Other_TPoX_Usage">other usage of TPoX</a> have been reported.</p>
<p><span style="text-decoration:underline;"><strong>Answer 2:</strong></span></p>
<p>TPoX is a very flexible and extensible tool for performance testing of relational databases, XML databases, and other systems. For example, if you have a populated relational database you can use the TPoX workload driver to parameterize, execute, and measure plain old SQL transactions with hundreds of simulated database users. I have used TPoX for a lot of relational performance testing, because it’s so easy to setup and measure concurrent workloads. The workload driver reports throughput, min/ax/avg response times, percentiles and confidence intervals for response times, and other useful metrics. Oh, and by the way, TPoX happens to include an XML data generator and a set of sample XML transactions, in case you&#8217;re interested in XML database performance.</p>
<p>&nbsp;</p>
<p>In the latest release, <strong>TPoX 2.1</strong>, we have further enhanced the extensibility of the TPoX Workload Driver. The XML data and XML transactions are still the same.</p>
<p>Some of the enhancements in TPoX 2.1 include:</p>
<ul>
<li>higher precision in reported response times</li>
<li>proper handling and counting of deadlocks, if any</li>
<li>easier post-processing of results in Excel or other spreadsheets software</li>
<li>new types of workload parameters such as random dates, random timestamps, sequences, etc.</li>
<li>in addition to SQL, SQL/XML, and XQuery, transactions can now be also supplied as <strong>Java plugins</strong>, allowing you to run and measure anything (concurrently!) that you can code in Java, such as:</li>
</ul>
<blockquote>
<ul>
<li>complex transactions that include application logic</li>
<li>calls to <strong>web services</strong> or <strong>message queues</strong></li>
<li>obtaining data from <strong>RSS</strong> or <strong>ATOM</strong> feeds</li>
<li>transactions against databases or <strong>content repositories</strong> that do not have a JDBC interface</li>
</ul>
</blockquote>
<p>We have already found these extensions extremely valuable for some of our own performance testing, and we&#8217;re happy to share them. You can <a href="http://sourceforge.net/projects/tpox/files/tpox/v2.1/">download TPoX 2.1</a> (free, open source) and find more detailed information in the release notes as well as the TPoX documentation that is included in the download.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1358&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/11/15/tpox-2-1-has-been-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>XML in Las Vegas !</title>
		<link>http://nativexmldatabase.com/2011/10/18/xml-in-las-vegas/</link>
		<comments>http://nativexmldatabase.com/2011/10/18/xml-in-las-vegas/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 22:33:55 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1349</guid>
		<description><![CDATA[The annual Information on Demand conference in Las Vegas (Oct 23-27, 2011) is always a great venue to get updated on the latest topics in data management. The IOD conference offers a broad range of technical sessions, business sessions, hands-on labs, and lots of networking opportunities. More than 200 customer speakers will present their first-hand [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1349&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The annual <a href="http://www-01.ibm.com/software/data/2011-conference/">Information on Demand conference</a> in Las Vegas (Oct 23-27, 2011) is always a great venue to get updated on the latest topics in data management. The IOD conference offers a broad range of technical sessions, business sessions, hands-on labs, and lots of networking opportunities. More than <a href="http://www-01.ibm.com/software/data/2011-conference/2011-customer-speakers.html">200 customer speakers </a>will present their first-hand experiences with IBM Software.</p>
<p>The conference is in the Mandalay Bay conventation center. Various topics around DB2 pureXML are covered in presentations and hands-on labs. Some of them are listed here:</p>
<p><span style="color:#333399;">2088A &#8211; DB2 pureXML for Beginners</span><br />
<span style="color:#333399;">Mon, Oct 24, 2011, 3:45 PM &#8211; 5:00 PM</span></p>
<p><span style="color:#333399;">1120B &#8211; DB2 pureXML: Develop Your Application Prototype in Minutes, not Days</span><br />
<span style="color:#333399;">Tue, Oct 25, 2011, 9:45 AM &#8211; 12:45 PM (hands-on lab)</span></p>
<p><span style="color:#333399;">1930A &#8211; DB2 for z/OS SOA Solutions Powered by pureXML and DataPower</span><br />
<span style="color:#333399;">Wed, Oct 26, 2011, 3:15 PM &#8211; 4:15 PM</span></p>
<p><span style="color:#333399;">2691A &#8211; Architecting with IBM pureXML and Temporal Data in DB2 10 for z/OS</span><br />
<span style="color:#333399;">Thu, Oct 27, 2011, 8:15 AM &#8211; 9:30 AM </span></p>
<p><span style="color:#333399;">2087B &#8211; Get Connected: Publishing Relational Data as XML Messages</span><br />
<span style="color:#333399;">Thu, Oct 27, 2011, 3:30 PM &#8211; 4:30 PM</span></p>
<p>If you&#8217;re going to IOD, don&#8217;t miss these sessions!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1349&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/10/18/xml-in-las-vegas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>Advanced SQL/XML: Joins and FLWOR Expressions in the XMLTABLE Function</title>
		<link>http://nativexmldatabase.com/2011/10/09/advanced-sqlxml-joins-and-flwor-expressions-in-the-xmltable-function/</link>
		<comments>http://nativexmldatabase.com/2011/10/09/advanced-sqlxml-joins-and-flwor-expressions-in-the-xmltable-function/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 03:23:31 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1336</guid>
		<description><![CDATA[If you look at existing documentation and examples of the XMLTABLE function, you find that most examples use simple XPath expressions inside the XMLTABLE function and rarely more complex XQuery expressions such as FLWOR expressions. This is also true for my 2 articles on XMLTABLE: XMLTABLE By Example, Part1 and Part2: http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/ http://www.ibm.com/developerworks/data/library/techarticle/dm-0709nicola/ Why is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1336&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you look at existing documentation and examples of the XMLTABLE function, you find that most examples use simple XPath expressions inside the XMLTABLE function and rarely more complex XQuery expressions such as FLWOR expressions. This is also true for my 2 articles on XMLTABLE:</p>
<p>XMLTABLE By Example, Part1 and Part2:<br />
<a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/">http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/</a><br />
<a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-0709nicola/">http://www.ibm.com/developerworks/data/library/techarticle/dm-0709nicola/</a></p>
<p>Why is that? Is it because XQuery expressions other than plain path expressions are never required in the XMLTABLE function? Well, let&#8217;s take a look at that question&#8230;</p>
<p>First, I do believe that many typical SQL/XML queries can indeed be coded with just regular XPath in the XMLTABLE function. I have seen that this is true in many real application deployments.</p>
<p>But, sometimes it can certainly be useful to embed more complex XQuery expressions than just XPath in an XMLTABLE function. For example, in my blog post &#8220;<a href="http://nativexmldatabase.com/2010/05/26/xml-profiling-how-to-get-a-list-of-all-elements-and-attributes/">How to get a list of all elements and attributes</a>&#8221; you saw that I used the XQuery <a href="http://www.w3.org/TR/xquery/#dt-comma-operator">comma operator</a> to construct a sequence from two expressions. In that case the comma expression was //(*,@*) to get all elements and all attributes. In the same post you also saw the use of the XQuery <a href="http://www.w3.org/TR/xquery/#id-conditionals">if-then-else</a> expression in the column definition of the XMLTABLE function.</p>
<p>Using FLWOR expression in the XMLTABLE function can be useful if you join and combine XML from two different XML columns. For example let&#8217;s consider the following two tables with te subsequent sample documents:</p>
<p><pre class="brush: sql;">

CREATE TABLE order(orderdetails XML);
CREATE TABLE product(description XML);

INSERT INTO order VALUES('
&lt;order&gt;
  &lt;orderNo&gt;123&lt;/orderNo&gt;
  &lt;item&gt;
    &lt;pid&gt;24TX98&lt;/pid&gt;
    &lt;quantity&gt;1&lt;/quantity&gt;
    &lt;price&gt;29.95&lt;/price&gt;
  &lt;/item&gt; 
  &lt;item&gt;
    &lt;pid&gt;901V8&lt;/pid&gt;
    &lt;quantity&gt;2&lt;/quantity&gt;
    &lt;price&gt;5.00&lt;/price&gt;
  &lt;/item&gt; 
&lt;/order&gt;');

INSERT INTO product VALUES('
&lt;product pid=&quot;24TX98&quot;&gt;
  &lt;name&gt;Outdoor paint&lt;/name&gt;
  &lt;description&gt;
    &lt;weight&gt;3kg&lt;/weight&gt;
    &lt;color&gt;white&lt;/color&gt;
  &lt;/description&gt;   
&lt;/product&gt;');

INSERT INTO product VALUES('
&lt;product pid=&quot;901V8&quot;&gt;
  &lt;name&gt;Paint brush&lt;/name&gt;
  &lt;description&gt;
    &lt;weight&gt;0.1kg&lt;/weight&gt;
  &lt;/description&gt;   
&lt;/product&gt;');

</pre></p>
<p>The order table contains one XML document per order, and the product table one XML document per product. Each product has a @pid attribute as a unique identifier, and  orders have /order/item/pid elements to specify which products have been ordered. Naturally, this allows us to perform a join between orders and products.</p>
<p>For example, the following query is a join to retrieve the product information for all the products that have been ordered in order 123:</p>
<p><pre class="brush: sql;">

SELECT product.description
FROM order, product
WHERE XMLEXISTS('$ORDERDETAILS/order[orderNo = 123]')
  AND XMLEXISTS('$DESCRIPTION/product[ @pid/fn:string(.) =
                   $ORDERDETAILS/order/item/pid/fn:string(.) ]');

</pre></p>
<p>This query returns one row (one XML document) for each product that is referenced in order 123.</p>
<p>Now, what if you want to combine data from an order document and the associated product documents, and return this information in one relational row per product?  For example, assume you want rows that show the product ID and product weight (from the product documents) as well as the price and quantity of that product in the order document.</p>
<p>In that case you could use an XQuery FLWOR expression to perform the join and combine the product and order information in the XMLTABLE function, as shown in the following query.</p>
<p>Since the product and order tables appear in the FROM clause of the query, the FLWOR expression references their XML columns through the variables $DESCRIPTION and $ORDERDETAILS. The return clause of the FLWOR expression constructs XML fragments that combine the desired elements and attributes from each matching pair of product and order documents. The constructed &lt;result&gt; elements are then input to the COLUMNS clause where they are broken up into relational columns.</p>
<p><pre class="brush: sql;">

SELECT T.*
FROM order, product,
     XMLTABLE('for $o in $ORDERDETAILS/order[orderNo = 123]/item
                for $p in $DESCRIPTION/product
                where $p/@pid/fn:string(.) = $o/pid/fn:string(.)
                return
                    &lt;result&gt;
                        {$p/@pid}
                        {$p/description/weight}
                        {$o/quantity}
                        {$o/price}
                    &lt;/result&gt;'
         COLUMNS
             prodid VARCHAR(15)  PATH '@pid',
             weight VARCHAR(5)   PATH 'weight',
             qty    INTEGER      PATH 'quantity',
             price  DECIMAL(6,2) PATH 'price')
         AS T;

   
PRODID          WEIGHT QTY         PRICE
--------------- ------ ----------- --------
24TX98          3kg              1    29.95
901V8           0.1kg            2     5.00

  2 record(s) selected.

</pre></p>
<p>It is worthwhile noting that you can produce the same result set without the use of FLWOR expressions, as shown in the next query. This query uses two XMLTABLE function, one for the desired order information and one for the desired product information. The key trick is that the two XMLTABLE function are joined on the product ID using the predicate [@pid = $p]. Without this predicate the two XMLTABLE functions would produce a Cartesian product, which is not desired.</p>
<p><pre class="brush: sql;">

SELECT T2.prodid, T2.weight, T1.qty, T1.price
FROM order, product,
     XMLTABLE('$ORDERDETAILS/order/item'
        COLUMNS
           prodid VARCHAR(15)  PATH 'pid',
           qty    INTEGER      PATH 'quantity',
           price  DECIMAL(6,2) PATH 'price')
     AS T1,
     XMLTABLE('$DESCRIPTION/product[@pid = $p]'
                                  PASSING T1.prodid AS &quot;p&quot;
        COLUMNS
           prodid VARCHAR(15)  PATH '@pid',
           weight VARCHAR(5)   PATH 'description/weight')
     AS T2;

 
                  
PRODID          WEIGHT QTY         PRICE
--------------- ------ ----------- --------
24TX98          3kg              1    29.95
901V8           0.1kg            2     5.00

  2 record(s) selected.

</pre></p>
<p>The join predicate between the two XMLTABLE functions can also be placed in the SQL WHERE clause:</p>
<p><pre class="brush: sql;">

SELECT T2.prodid, T2.weight, T1.qty, T1.price
FROM order, product,
     XMLTABLE('$ORDERDETAILS/order/item'
        COLUMNS
           prodid VARCHAR(15)  PATH 'pid',
           qty    INTEGER      PATH 'quantity',
           price  DECIMAL(6,2) PATH 'price')
     AS T1,
     XMLTABLE('$DESCRIPTION/product'
        COLUMNS
           prodid VARCHAR(15)  PATH '@pid',
           weight VARCHAR(5)   PATH 'description/weight')
     AS T2
WHERE T1.prodid = T2.prodid;       

</pre></p>
<p>However, this query applies the join predicate <em>after</em> the XMLTABLE functions have produced their rows, which can be slower than the previous query where the predicate was in the XMLTABLE function itself.</p>
<p>You can find many more examples of the XMLTABLE function, XML joins, and joins between XML and relational columns in Chapter 9 of the <a href="http://tinyurl.com/pureXML">DB2 pureXML Cookbook</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1336/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1336&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/10/09/advanced-sqlxml-joins-and-flwor-expressions-in-the-xmltable-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>At your service: REST with DB2 pureXML!</title>
		<link>http://nativexmldatabase.com/2011/09/29/rest-with-db2-purexml/</link>
		<comments>http://nativexmldatabase.com/2011/09/29/rest-with-db2-purexml/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 06:59:53 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1321</guid>
		<description><![CDATA[Undeniably, XML is the message format of choice for many service-oriented architectures and application integration efforts. Also, many SOA and web service implementaions use REST as the protocol for accessing URL-addressable resources and services. REST stands for Representational State Transfer and is built on top of HTTP, which acts as the underlying transport layer. With [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1321&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Undeniably, XML is the message format of choice for many service-oriented architectures and application integration efforts. Also, many SOA and web service implementaions use REST as the protocol for accessing URL-addressable resources and services. REST stands for Representational State Transfer and is built on top of HTTP, which acts as the underlying transport layer.</p>
<p>With a new set user-defined functions (UDFs) in DB2, it has become very simple to issue REST requests directly from your SQL statements or DB2 stored procedures. This enables DB2 to easily interact with REST-based services and integrate information from the web or URL-based resources into the database.</p>
<p>The new REST UDFs allow you to receive and provide information in binary format (BLOB) or textual format (CLOB), which includes but is not limited to XML. The basic REST UDFs are scalar functions that perform the simple HTTP operations GET, POST, PUT, and DELETE. These UDFs are:</p>
<ul>
<li>DB2XML.HTTPGETCLOB</li>
<li>DB2XML.HTTPPOSTCLOB</li>
<li>DB2XML.HTTPPUTCLOB</li>
<li>DB2XML.HTTPDELETECLOB</li>
</ul>
<ul>
<li>DB2XML.HTTPGETBLOB</li>
<li>DB2XML.HTTPPOSTBLOB</li>
<li>DB2XML.HTTPPUTBLOB</li>
<li>DB2XML.HTTPDELETEBLOB</li>
</ul>
<p>Each of these functions take a URL and, optionally, an HTTP header as input paramaters. Additionally, the POST and PUT functions have a third parameter for the BLOB or CLOB data that you want to upload.</p>
<p>The REST UDFs are implemented in Java and support HTTP as well as HTTPS with SSL encryption.</p>
<p>When you use these UDFs in SQL statements to receive information, you can:</p>
<ul>
<li>insert the information into DB2 tables</li>
<li>use the information as a parameter to search for related data in DB2</li>
<li>join the information with existing data in DB2</li>
<li>process the information in a stored procedure</li>
<li>or use the information in any other way that SQL provides</li>
</ul>
<p>In particular, if the information is in XML format you can apply any DB2 pureXML functions to it, such as:</p>
<ul>
<li>the XMLQUERY function to extract pieces from the XML message</li>
<li>the XMLTABLE function to split the XML into smaller XML pieces</li>
<li>the XMLTABLE function to shred the XML into relational tables</li>
<li>the XMLVALIDATE function to validate the XML against an XML Schema</li>
<li>etc.</li>
</ul>
<p>If you are interested and want to try this for yourself, read the following article:<br />
<strong> &#8220;Accessing HTTP and RESTful services from DB2: Introducing the REST user-defined functions for DB2&#8243;</strong><br />
<a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-1105httprestdb2/"> http://www.ibm.com/developerworks/data/library/techarticle/dm-1105httprestdb2/</a></p>
<p>This article describes the REST functions for DB2 in more detail and presents several concrete usage examples. The UDFs themselves are available for download at the bottom of this article.</p>
<p>Enjoy your REST !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1321&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/09/29/rest-with-db2-purexml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>DB2 pureXML &#8211; Rich in Proteins!</title>
		<link>http://nativexmldatabase.com/2011/09/12/db2-purexml-rich-in-proteins/</link>
		<comments>http://nativexmldatabase.com/2011/09/12/db2-purexml-rich-in-proteins/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 06:20:01 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1316</guid>
		<description><![CDATA[How much protein is in a steak? Well, a 6-ounce steak can contain about 38 grams worth of protein. How much protein does salmon contain? Approximately 34 gram of protein in a 6 ounce piece of salmon. How much protein can you find in lentils? A cup of cooked lentils has 18 rams of protein. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1316&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How much protein is in a steak? Well, a 6-ounce steak can contain about 38 grams worth of protein.</p>
<p>How much protein does salmon contain? Approximately 34 gram of protein in a 6 ounce piece of salmon.</p>
<p>How much protein can you find in lentils? A cup of cooked lentils has 18 rams of protein.</p>
<p>And how much protein can you find in <strong>DB2 pureXML</strong>? Tons! Hundreds of Gigabytes and soon over a 1TB of proteins!</p>
<p>It&#8217;s true, DB2 pureXML is an excellent source for proteins. DB2 can store, compress, and index the proteins so that you always find the right ones quickly when you need some.</p>
<p>What distinguishes DB2 from a steak is that DB2 stores all proteins in XML  or in a hybrid XML/relational format! This enables members of the biological research community to analyze and compare the structure and composition of protein molecules. The findings can help them explain diseases, develop new drugs, or understand the interactions between different proteins.</p>
<p>The protein data is publicly available from the Protein Data Bank (PDB) which is world-wide repository of structural protein data. To facilitate data exchange and flexibility, the data is available in XML.</p>
<p>Typically one XML document describes a single protein molecule. Such a document includes detailed information about all the atoms that the protein consists of, which can be hundreds or sometimes thousands of atoms. And to represent the <em>structure</em> of the protein, the 3-dimensional spatial coordinates of each atom are included as well, resulting in XML documents that can be hundreds of MB in size to describe a single protein.</p>
<p>Searching and analyzing such amounts of complex information is a challenge. To tackle this challenge, researchers in Germany decided to harness the hybrid XML/relational capabilities of DB2 to efficiently store and query the protein data. I was happy to assist them to get the most out of DB2 pureXML.</p>
<p>The article &#8220;<a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-1109proteindatadb2purexml/">Managing the Protein Data Bank with DB2 pureXML</a>&#8221; describes the database design and optimization that facilitate protein data analysis in a scalable manner. Even if you&#8217;re not a biologist (I&#8217;m not!), the article is an interesting cases study in how a real-world data management problem has been mapped to the hybrid features of the DB2 database system.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1316&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/09/12/db2-purexml-rich-in-proteins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
		<item>
		<title>Quantified expressions in XQuery: When &#8220;some&#8221; and &#8220;every&#8221; satisfy!</title>
		<link>http://nativexmldatabase.com/2011/08/29/quantified-expressions-in-xquery-when-some-and-every-satisfy/</link>
		<comments>http://nativexmldatabase.com/2011/08/29/quantified-expressions-in-xquery-when-some-and-every-satisfy/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 06:32:25 +0000</pubDate>
		<dc:creator>Matthias Nicola</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nativexmldatabase.com/?p=1305</guid>
		<description><![CDATA[If you are familiar with SQL you have probably seen quantified SQL predicates that compare a single value with a set of values. For example, the following SQL query returns all rows from table1 where col1 is greater than all values in col2 of table2. SELECT * FROM table1 WHERE col1  &#62; ALL (SELECT col2 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1305&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are familiar with SQL you have probably seen <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000747.html">quantified SQL predicates</a> that compare a single value with a set of values. For example, the following SQL query returns all rows from <span style="color:#0000ff;">table1</span> where <span style="color:#0000ff;">col1</span> is greater than <em>all</em> values in <span style="color:#0000ff;">col2</span> of <span style="color:#0000ff;">table2</span>.</p>
<p><span style="color:#0000ff;">SELECT *</span><br />
<span style="color:#0000ff;">FROM table1</span><br />
<span style="color:#0000ff;">WHERE col1  &gt; ALL (SELECT col2 FROM table2)</span></p>
<p>And if you replace the keyword ALL with the keyword SOME, then the query above returns all rows from <span style="color:#0000ff;">table1</span> where <span style="color:#0000ff;">col1</span> is greater than <em>at least one</em> of the values in <span style="color:#0000ff;">col2</span> of <span style="color:#0000ff;">table2</span>.</p>
<p>These comparisons are also known as <em>universal quantification</em> (&#8220;ALL&#8221;) and <em>existential</em> <em>quantification</em> (&#8220;SOME&#8221;), respectively.</p>
<p>Similar quantified comparisons are possible in XQuery too, but the syntax is slightly different. In XQuery you have the keywords &#8220;every &#8230; satisfies &#8230;.&#8221; for  universal quantification and &#8220;some &#8230; satisfies &#8230;&#8221; for existential quantification. Let&#8217;s use the following table and two simple sample documents to explore how they work:</p>
<p><span style="color:#0000ff;">create table customer(doc XML);</span></p>
<p><span style="color:#0000ff;">insert into customer values(&#8216;</span><br />
<span style="color:#0000ff;">&lt;customer id=&#8221;1&#8243;&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;cell&#8221;&gt;408-516-4963&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;cell&#8221;&gt;408-087-1234&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;cell&#8221;&gt;408-111-222&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">&lt;/customer&gt;</span><br />
<span style="color:#0000ff;">&#8216;);</span></p>
<p><span style="color:#0000ff;">insert into customer values(&#8216;</span><br />
<span style="color:#0000ff;">&lt;customer id=&#8221;2&#8243;&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;home&#8221;&gt;408-516-4963&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;cell&#8221;&gt;408-087-1234&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">    &lt;phone type=&#8221;office&#8221;&gt;408-111-222&lt;/phone&gt;</span><br />
<span style="color:#0000ff;">&lt;/customer&gt;</span><br />
<span style="color:#0000ff;">&#8216;);</span></p>
<p>Now assume that we want to find customers where <em>all</em> their phone numbers are of type &#8220;cell&#8221;. We can code a corresponding query in XQuery or in SQL/XML notation as follows:</p>
<p><span style="color:#0000ff;">xquery</span><br />
<span style="color:#0000ff;">for $c in db2-fn:xmlcolumn(&#8220;CUSTOMER.DOC&#8221;)/customer</span><br />
<span style="color:#0000ff;"> where every $p in $c/phone satisfies $p/@type = &#8220;cell&#8221;</span><br />
<span style="color:#0000ff;"> return $c;</span></p>
<p><span style="color:#0000ff;">select *</span><br />
<span style="color:#0000ff;"> from customer</span><br />
<span style="color:#0000ff;"> where xmlexists (&#8216;$DOC/customer[ every $p in ./phone satisfies $p/@type = "cell"]&#8216;);</span></p>
<p>Both queries return just the first of the two customer documents. The second document is not selected because not all of its phone elements have a @type attribute with the value &#8220;cell&#8221;.</p>
<p>The quantified expression <span style="color:#0000ff;">every $p in $c/phone satisfies $p/@type = &#8220;cell&#8221;</span> means that <span style="color:#0000ff;">$p</span> iterates over all the items in the sequence <span style="color:#0000ff;">$c/phone</span>,  and for each such <span style="color:#0000ff;">$p</span> the predicates<span style="color:#0000ff;"> $p/@type = &#8220;cell&#8221;</span> must be true.</p>
<p>If we want to return all documents where <em>at least one</em> of the phone number is of type &#8220;cell&#8221; (existential quantification!), then we can simply replace the keyword &#8220;every&#8221; with the keyword &#8220;some&#8221;, such as in the following query:</p>
<p><span style="color:#0000ff;">select *</span><br />
<span style="color:#0000ff;"> from customer</span><br />
<span style="color:#0000ff;"> where xmlexists (&#8216;$DOC/customer[ some $p in ./phone satisfies $p/@type = "cell"]&#8216;);</span></p>
<p>This query returns both our sample documents, because both documents contain at least one phone element where the @type attribute has the value &#8220;cell&#8221;. Since XPath uses existential quantification by default, you can often omit the &#8220;some &#8230; satisfies &#8230;&#8221; and obtain the same result with an ordinary path expression, like this:</p>
<p><span style="color:#0000ff;">select *</span><br />
<span style="color:#0000ff;"> from customer</span><br />
<span style="color:#0000ff;"> where xmlexists (&#8216;$DOC/customer[phone/@type = "cell"]&#8216;);</span></p>
<p>For more information, use the following resources.</p>
<p>DB2 Information Center &#8211; Quantified Expressions:<br />
<a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.xml.doc/doc/xqrquanexp.html">http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.xml.doc/doc/xqrquanexp.html</a></p>
<p>XQuery specification of quantified expressions:<br />
<a href="http://www.w3.org/TR/xquery/#id-quantified-expressions">http://www.w3.org/TR/xquery/#id-quantified-expressions</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/purexml.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/purexml.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/purexml.wordpress.com/1305/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nativexmldatabase.com&amp;blog=3215007&amp;post=1305&amp;subd=purexml&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nativexmldatabase.com/2011/08/29/quantified-expressions-in-xquery-when-some-and-every-satisfy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0fa2a8696cf3869ab2ded9243422d875?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Matthias</media:title>
		</media:content>
	</item>
	</channel>
</rss>
