"How To Get Attribute Value Of Root Element"?

Discussion in 'Javascript' started by pbd22, Jul 3, 2007.

  1. pbd22

    pbd22 Guest

    Hi.

    Could somebody tell me how to get an attribute value from an
    XML root element? for example, what would the javascript look
    like to get the value "first" from the below root element? I thank
    you.

    <root id='first'>
    <child id='1'>i am a child</child>
    <child id='2'>i last a while</child>
    </child>
    pbd22, Jul 3, 2007
    #1
    1. Advertising

  2. pbd22 wrote:

    > Could somebody tell me how to get an attribute value from an
    > XML root element? for example, what would the javascript look
    > like to get the value "first" from the below root element? I thank
    > you.
    >
    > <root id='first'>
    > <child id='1'>i am a child</child>
    > <child id='2'>i last a while</child>
    > </child>


    If you have an XML DOM document then use
    xmlDocument.documentElement.getAttribute('id')

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 3, 2007
    #2
    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.

Share This Page