Getting element's name in XPATH

后端 未结 2 830
余生分开走
余生分开走 2020-11-28 12:36

If I selected an element using XPATH how can I get its name?
I mean something like text() function in //element/[@id=elid]/text().

相关标签:
2条回答
  • 2020-11-28 13:18

    Use name(). (Find docs for newer versions of the XPath language here.)

    Here are modified versions of your example:

    Works in XPath 2.0 only:

    //element/*[@id='elid']/name()
    

    Works in XPath 1.0 and 2.0:

    name(//element/*[@id='elid'])
    

    You could also use local-name() which returns the local part of the expanded name (without any namespace prefix).

    0 讨论(0)
  • 2020-11-28 13:21

    The tag names tree can also be obtained with

    echo "du //Element/*" | xmllint --shell response-02.xml
    Ele1
        id
        name
        Nested1
            id
            name
    Ele2
    
    0 讨论(0)
提交回复
热议问题