Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Xml.XPath.XPathException:执行SelectSingleNode(“艺术家”“作者”)时,表达式必须计算为节点集_C#_Xml_Xpath_Selectsinglenode - Fatal编程技术网

C# System.Xml.XPath.XPathException:执行SelectSingleNode(“艺术家”“作者”)时,表达式必须计算为节点集

C# System.Xml.XPath.XPathException:执行SelectSingleNode(“艺术家”“作者”)时,表达式必须计算为节点集,c#,xml,xpath,selectsinglenode,C#,Xml,Xpath,Selectsinglenode,有人能解释一下为什么这不起作用吗 我在执行死刑 XmlNode xmlNode = xmlDocument.SelectSingleNode("//(artist|author)"); 我得到 System.Xml.XPath.XPathException: Expression must evaluate to a node-set. 据我所知,您可以在XPath查询的顶层使用“|”,因此请尝试该查询 "//artist|//author" 再见,递归搜索(//)的速度不是很快,所

有人能解释一下为什么这不起作用吗

我在执行死刑

XmlNode xmlNode = xmlDocument.SelectSingleNode("//(artist|author)");
我得到

System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
据我所知,您可以在XPath查询的顶层使用“|”,因此请尝试该查询

    "//artist|//author"
再见,递归搜索(//)的速度不是很快,所以请确保您的dom文档很小

更新:

我在网上查了一下:

3.3节点集

位置路径可以用作 表情。表达式返回 由路径选择的节点集

|运算符计算 它的操作数,必须是节点集

这意味着无论您在“|”的左边和右边写什么,都需要能够单独作为xpath查询使用,“|”就可以从中创建联合

具体来说,您不能说“递归搜索(名为author或名为artist的内容)”,因为“名为author的内容”的计算结果不是xpath查询(节点集)的结果

  • //artist |//author
    使用XPATH 1.0和2.0
  • //(艺术家|作者)
    使用XPATH 2.0

  • 微软是一家懒惰的公司。他们的框架只支持XPATH 1.0

    可能//(艺术家|作者)计算为0个节点?不,我在其他XPATH计算程序上测试了它:使用“//艺术家|//author”会发生什么?请尝试检查调试器(使用xmlDoc.SelectNodes),因为在某些边缘情况下,不同的库可能表现不同,而不是XPATH 2.0,因为它们“懒惰”——当然。
        "//artist|//author"