xml XML XQuery,FLWOR查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml XML XQuery,FLWOR查询相关的知识,希望对你有一定的参考价值。

<!-- XQuery is the query syntax for querying XML data. Based on XPath expressions. -->

<!-- using this XML as an example: -->

<?xml version="1.0" encoding="ISO-8859-1"?>
<order id="123456" date="2015-01-01">
  <salespersonid="123">
    <name>Naomi Sharp</name>
  </salesperson>
  <customer id="921">
    <name>Dan Drayton</name>
  </customer>
  <items>
    <itemid="268" quanitity="2"/>
    <itemid="561" quanitity="1"/>
    <itemid="127" quanitity="2"/>
  </items>
</order>

<!-- there are a few ways to find things within this XML using XQuery:

/order/salesperson/name - find order, then salesperson element, then name element below salesperson

/order/customer/@id - find order, go to customer element, and then find the attribute id (@ identifies it as an attribute

/order//name - find order and then pull all elements called named, regardless of where they are on the tree, as long as they're below order

/order/items/items[2] - find order, then items element, and then find a specific instance of that element. For example, if you have multiple item elements, this will find the second item based on ordinal position.

/order/items/item[@quantity > 1] - find order, then items element, and then find all items elements where the quantity attribute is more than one

-->

<!-- there are also FLWOR queries. Let is in parenthesis since it is not supported in SQL Server.

XQuery FLWOR Queries - For, (Let), Where, Order By, Return

Example of a FLWOR query:

for @i in /order/items/item
where @i/@quantity > 1
order by @i/@id
return @i

Result of the query:
<itemid="127" quanitity="2"/>
<itemid="268" quanitity="2"/>

-- >

以上是关于xml XML XQuery,FLWOR查询的主要内容,如果未能解决你的问题,请参考以下文章

使用 XPath/XQuery 过滤 XML 列上的 SQL 查询

XQuery 如何使用 WHERE 查询获取整个 xml 文档

sql 使用XQuery方法查询,值,存在,节点在SQL Server中查询XML

sql 2005数据库 如何操作xml

T-SQL XQuery (XML路径查询) (转)http://blog.csdn.net/Beirut/article/details/8150116

eXist DB & XQuery:带有属性的 xml-root 导致没有结果