【发布时间】:2013-04-09 14:58:45
【问题描述】:
在下面的 XML 中:
<company>
<customers>
<customer cno="2222">
<cname>Charles</cname>
<street>123 Main St.</street>
<city>Wichita</city>
<zip>67226</zip>
<phone>316-636-5555</phone>
</customer>
<customer cno="1000">
<cname>Bismita</cname>
<street>Ashford Dunwoody</street>
<city>Wichita</city>
<zip>67226-1555</zip>
<phone>000-000-0000</phone>
</customer>
</customers>
</company>
我需要获取作为属性的客户编号。
在 XPath 中我知道它是 /company/customers/customer/@cno,在 XQuery 中我尝试了下面的表达式但对我不起作用:
for $c in /company/customers/customer
return $c/@cno
【问题讨论】:
-
XQuery 使用纯 XPath;你的尝试对我有用。
return $c带给你什么? -
我正在为此使用 EditX 软件,但它显示错误“无法创建其父节点为文档节点的属性节点。”你能告诉我你用哪个工具试试这个,所以我可以切换到那个工具。可能是特定于工具的问题。
-
有时搜索确切的错误信息会产生奇迹。这个问题对我来说是第一个问题,我相信它也会为你做同样的事情。
-
您也可以使用较短的
/company/customers/customer/@cno/data(),它不需要显式循环。