xpath to get Node containing text

后端 未结 2 712
梦毁少年i
梦毁少年i 2020-12-05 06:09

I tried to search for nodes containing text \'Yahoo\' under \'/doc/story/content\', it returns \'content\' node, but I need exact text node that contains \'Yahoo\' or it\'s

相关标签:
2条回答
  • 2020-12-05 06:52

    Since you need all textNodes only which contain the text Yahoo, use the following XPath.

    //text()[contains(., 'Yahoo')]
    

    This should return you all the textNodes only which contains Yahoo (case-sensitive) in it.

    0 讨论(0)
  • 2020-12-05 07:04

    Your XML is malformed. </content></doc></story> should be </content></story></doc>.

    Apart from that, the XPath you would want is

    /doc/story/content//*[contains(., 'Yahoo')]
    

    (select any descendant of <content> which contains the text "Yahoo" -- this will select the <p>)

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