XPath operator “!=”. How does it work?

后端 未结 2 900
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 19:29

XML document:


       
        Hello!   
     

         
        
             


        
2条回答
  •  借酒劲吻你
    2020-12-08 20:17

    From the XPath spec:

    If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.

    This means that if the node-set is empty (as in your cases C and D), the result of the boolean expression will be false, since there is no node to which the inequality can apply.

    You can work around this behaviour and get the result you want using an expression like:

    count(/doc/C/Node) = 0 or /doc/C/Node != 'abcd'
    

提交回复
热议问题