System.Xml.XPath.XPathException:执行 SelectSingleNode(“//(artist|author)”) 时,表达式的计算结果必须为节点集
有人可以解释一下为什么这不起作用吗?
我正在执行
XmlNode xmlNode = xmlDocument.SelectSingleNode("//(artist|author)");
并且我得到了,
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
但是即使有很多艺术家节点,这也有效并且不会引发异常
XmlNode xmlNode = xmlDocument.SelectSingleNode("//artist");
Can somebody explain me why is this not working?
I'm executing
XmlNode xmlNode = xmlDocument.SelectSingleNode("//(artist|author)");
and I get
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
but this works and does not raise the exception even when there are many artist nodes
XmlNode xmlNode = xmlDocument.SelectSingleNode("//artist");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您可以使用“|” 就在 XPath 查询的顶层,因此请尝试查询再见,
递归搜索 (//) 的方式不是很快,因此请确保您的 dom 文档很小。
更新:
我在 规范 中查找了它:
这意味着您在“|”左右写的任何内容 需要单独用作 xpath 查询,即“|” 然后从中创建联合。
具体来说,您不能说“递归搜索(称为作者的东西或称为艺术家的东西)”,因为“称为作者的东西”不会评估 xpath 查询(节点集)的结果。
To my knowledge you can use '|' just at the top level of an XPath Query, so try the query
Bye the way doing recursive searches (//) isn't very fast, so make sure your dom document is small.
Update:
I looked it up in the specification:
That means whatever you write left and right of "|" needs to be usable as an xpath query on its own, the "|" then just creates the union from it.
Specifically you can not say "search recursively for (something called author OR something called artist)" because "something called author" does not evaluate to the result of an xpath-query (a node set).
//artist|//author
适用于 XPATH 1.0 和 2.0//(artist|author)
适用于 XPATH 2.0Microsoft 是一家懒惰的公司。 他们的框架仅支持 XPATH 1.0
//artist|//author
works with XPATH 1.0 and 2.0//(artist|author)
works with XPATH 2.0Microsoft is a lazy corporation. Their framework support only XPATH 1.0