Getting element's name in XPATH

◇◆丶佛笑我妖孽 提交于 2019-11-26 09:47:15

问题


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


回答1:


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).




回答2:


The tag names tree can also be obtained with

echo "du //Element/*" | xmllint --shell response-02.xml
Ele1
    id
    name
    Nested1
        id
        name
Ele2


来源:https://stackoverflow.com/questions/7984508/getting-elements-name-in-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!