0

我有以下 xml 文档,我需要一个 xquery 表达式来知道文档中有多少元素类型

    <category>
    <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
</CD>
<CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
</CD>
<CD>
  <book id="bk101">
  <author>Gambardella, Matthew</author>
  <title>XML Developer's Guide</title>
  <genre>Computer</genre>
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <description>An in-depth look at creating applications 
  with XML.</description>
 </book>

 </category>

所以我需要从查询中得到的返回值是cd and book. 有人可以帮忙吗?

4

1 回答 1

1

使用 XQuery(或 XPath 2.0)distinct-values(/category/*/local-name())就足够了,结果是一个字符串值序列CD, book

于 2012-06-20T12:15:16.160 回答