469,360 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

Extract element name by XPath expression

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 15041


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

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Perfect! Thanks a lot.
Daniel

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Anna | last post: by
9 posts views Thread by Stefan Franke | last post: by
2 posts views Thread by gimme_this_gimme_that | last post: by
1 post views Thread by FaensenD | last post: by
4 posts views Thread by piramido | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.