If I selected an element using XPATH how can I get its name?
I mean something like text() function in //element/[@id=elid]/text().
If I selected an element using XPATH how can I get its name? I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
Works in XPath 1.0 and 2.0+*:
*If using 2.0+, the expression
//element/*[@id='elid']must only return one element. Otherwise you’ll get an error likeA sequence of more than one item is not allowed as the first argument of fn:name()You could also use
local-name()which returns the local part of the expanded name (without any namespace prefix).