XQueryX

XQueryX is an alternate, XML syntax to represent XQuery queries. It is not covered in detail in this book because it is unlikely that most query authors will want to write XQueryX by hand. However, it may be useful as a syntax used by processors for storing and/or transferring queries because XML is easier to parse and/or transform than a non-XML syntax. It can also be useful for embedding queries in XML documents.

A simple FLWOR is shown in Example 22-1.

Example 22-1. Simple FLWOR

for $product in doc("catalog.xml")//product
order by $product/name
return $product/number

The equivalent XQueryX is shown in Example 22-2. As you can see, the XQueryX syntax is far more verbose, and breaks the query down to a very granular level, with at least one element for every expression.

Example 22-2. Partial XQueryX equivalent of Example 22-1

<?xml version="1.0"?>
<xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2005/XQueryX
                                http://www.w3.org/2005/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:flworExpr>
        <xqx:forClause>
          <xqx:forClauseItem>
            <xqx:typedVariableBinding>
              <xqx:varName>product</xqx:varName>
            </xqx:typedVariableBinding>
            <xqx:forExpr>
              <xqx:pathExpr>
                <xqx:argExpr>
                  <xqx:functionCallExpr>
                    <xqx:functionName>doc</xqx:functionName>
                    <xqx:arguments>
                      <xqx:stringConstantExpr>
                        <xqx:value>catalog.xml</xqx:value>
                      </xqx:stringConstantExpr>
                    </xqx:arguments>
                  </xqx:functionCallExpr>
                </xqx:argExpr>
                <xqx:stepExpr>
                  <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
                  <xqx:anyKindTest/>
                </xqx:stepExpr>
                <xqx:stepExpr>

                  <xqx:xpathAxis>child</xqx:xpathAxis>
                  <xqx:nameTest>product</xqx:nameTest>
                </xqx:stepExpr>
              </xqx:pathExpr>
            </xqx:forExpr>
          </xqx:forClauseItem>
        </xqx:forClause>  <!-- ... --->

For more information on XQueryX, see the recommendation at http://www.w3.org/TR/xqueryx. If you do use XQueryX, the W3C provides a handy converter to convert XQuery to XQueryX, found at http://www.w3.org/2005/qt-applets/xqueryApplet.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.77.208