Professional XML (Programmer to Programmer)

In literal XML constructors, you can use curly braces ({}) to add content that is computed when the query is run. This is called an enclosed expression. For example, in the previous example, if you want all of the <Name> elements to appear within an XML root element named <ProductNames>. This could be accomplished with the following XQuery expression:

<ProductNames> { doc("Products.xml")/Products/Product[@Category="Socks"]//Name } </ProductNames>

With this addition, the output would be as follows:

<ProductNames> <Name>Mountain Bike Socks, M</Name> <Name>Mountain Bike Socks, L</Name> </ProductNames>

Note that in this query, you used curly braces around the XPath expression within the <ProductNames> element. The braces denote that the content within the braces is an XQuery expression, and not literal content. For example, the following query omits the braces:

<ProductNames> doc("Products.xml")/Products/Product[@Category="Socks"]//Name </ProductNames>

The output of this query would be as follows:

<ProductNames> doc("Products.xml")/Products/Product[@Category="Socks"]//Name </ProductNames>

Категории