xpath:previous-sibling-or-self

时间:2014-10-27 20:29:59

标签: .net xpath

我想在我的xpath中使用preceding-sibling-or-self功能,而我正在使用../(self::*|preceding-sibling::*)并且它正在给我Expression must evaluate to a node-set.,所以我一定做错了。

这个炸弹无论你在哪个上下文节点或xml是什么样的。我想在/之后使用此功能,所以我需要正确的语法。

xpath表达式(self::*|preceding-sibling::*)没有给出错误,因此它与我尝试使用它的xpath中的位置有关。

编辑:

我的错误实际上更基本。如果没有该错误,您甚至无法../(.|.)。一般来说,我想去一个节点,然后从那里查看一组节点。该错误似乎与在斜杠|之后尝试使用union运算符/相关联。

1 个答案:

答案 0 :(得分:5)

在XPath中,如果要使用union运算符,则必须在路径的开头使用它。

(self::*|preceding-sibling::*)/Child没问题。

如果您需要执行Something/(self::*|preceding-sibling::*)/Child,则必须将左侧部分展开:

(Something/self::*|Something/preceding-sibling::*)/Child