XPath - Selecting elements that equal a value

前端 未结 2 667
太阳男子
太阳男子 2020-12-04 10:22

In Xpath, I am wanting to select elements that equal a specific value.

Sample XML data:


    
        <         


        
2条回答
  •  被撕碎了的回忆
    2020-12-04 10:29

    The XPath spec. defines the string value of an element as the concatenation (in document order) of all of its text-node descendents.

    This explains the "strange results".

    "Better" results can be obtained using the expressions below:

    //*[text() = 'qwerty']
    

    The above selects every element in the document that has at least one text-node child with value 'qwerty'.

    //*[text() = 'qwerty' and not(text()[2])]
    

    The above selects every element in the document that has only one text-node child and its value is: 'qwerty'.

提交回复
热议问题