XPath selection by innertext

后端 未结 3 1235
南方客
南方客 2020-12-24 10:34

I\'m trying to extract an element with a particular innertext from a parsed XML document. I know that I can select an element that has a child with a particular innertext u

相关标签:
3条回答
  • 2020-12-24 11:09

    Have you tried this?

    //myparent/mychild[text() = 'foo']
    

    Alternatively, you can use the shortcut for the self axis:

    //myparent/mychild[. = 'foo']
    
    0 讨论(0)
  • 2020-12-24 11:20

    Matt said it, but the full solution:

    //myparent[mychild='foo']/mychild
    
    0 讨论(0)
  • 2020-12-24 11:21

    You might consider using the contains function to return true/false if the test was found like so:

    //mychild[contains(text(),'foo')]
    

    See XSLT, XPath, and XQuery Functions for functions reference

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