Returning a Slice of XML With XQuery

Instead of retrieving the full XML document, you can apply an XQuery and retrieve the resulting partial document. To execute an XQuery, you must set the xquery and xml query variables.

Consider this XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>

The following query,

?query={"_id":new ObjectId("4d484fcfe7bd792987408a76"}&xquery=for
$x in /a return $x/b&xml=true
returns the following:

<?xml version="1.0" encoding="UTF-8" ?>
<XQueryResult>
   <item>
      <b>test</b>
   </item>
</XQueryResult>

The HTTP request is as follows:

http://localhost:2222/
?query={%22_id%22:new%20ObjectId(%224d49af7ce5397929bad5421e%22)}&xquery=
for%20$x%20in%20/a%20return%20$x/b&xml=true

For more information on XQuery, see the XQuery agent documentation.


iWay Software