XPath - Selecting elements that equal a value

前端 未结 2 659
太阳男子
太阳男子 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'.

    0 讨论(0)
  • Try

    //*[text()='qwerty'] because . is your current element

    0 讨论(0)
提交回复
热议问题