Extract element name by XPath expression

D

Daniel Frey

Hello,

I'd like to extract the name of an indirectly addressed element by
subsequently using the childs position:

001 <a>
002 <b1/>
003 <b2/>
004 <b3/>
005 </a>

I.e. I tried for the first sub-element:

001 /a/*[1]/text()

but that does return some odd characters, mainly the linefeed and some
spaces. Do you know a way to do that?

Thanks
Daniel Frey
 
M

Martin Honnen

Daniel Frey wrote:

I'd like to extract the name of an indirectly addressed element by
subsequently using the childs position:

001 <a>
002 <b1/>
003 <b2/>
004 <b3/>
005 </a>

I.e. I tried for the first sub-element:

001 /a/*[1]/text()

but that does return some odd characters, mainly the linefeed and some
spaces.

How are you evaluating your XPath expressions then?
I think /a/*[1] would give the <b1 /> element and as it is empty
/a/*[1]/text() should give an empty nodeset.

As for accessing the name of a node there are functions in XPath to do
that, local-name() for instance e.g.
local-name(/a/*[1])
see the XPath documentation here:
<http://www.w3.org/TR/xpath#function-local-name>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top