Extract element name by XPath expression

Discussion in 'XML' started by Daniel Frey, Jan 17, 2005.

  1. Daniel Frey

    Daniel Frey Guest

    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!
    Daniel Frey, Jan 17, 2005
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jan 17, 2005
    #2
    1. Advertising

  3. Daniel Frey

    Daniel Frey Guest

    Perfect! Thanks a lot.
    Daniel

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Daniel Frey, Jan 17, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    3
    Views:
    11,924
    vforvikash
    Dec 29, 2008
  2. Marc A. Criley
    Replies:
    0
    Views:
    553
    Marc A. Criley
    Dec 30, 2004
  3. Ian Wilson
    Replies:
    2
    Views:
    545
    Ian Wilson
    Jul 26, 2007
  4. HANM
    Replies:
    2
    Views:
    698
    Joseph Kesselman
    Jan 29, 2008
  5. Replies:
    6
    Views:
    155
Loading...

Share This Page