dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: walking the tree - easy question?

  1. #1
    Member
    Join Date
    Jul 2000
    Posts
    90

    walking the tree - easy question?

    Hi
    I'm trying to learn how to walk the tree and not use the ignoreWhiteSpace option in Flash but I'm a little confused.
    Here is the XML I'm using:

    <xml>
    <name>Bob</name>
    <address>here</address>
    </xml>

    I'm loading that in to an XML object called XMLDoc.
    I want to get to the info "Bob". If I just do this:
    trace(XMLDoc.firstChild);
    then then whole thing (including the XML tags) is displayed in the output window, but I thought the path to "Bob" was
    Code:
    firstChild(whitespace), nextSibling(<name>), firstChild(whiteSpace), nextSibling("Bob")
    but this is just returning "undefined". Can anyone tell me what I'm doing wrong?

    nb - obviously I'm writing the above as:
    XMLDoc.firstChild.nextSibling.firstChild.nextSibli ng

    thanks
    Last edited by Flash Bastard; 11-26-2002 at 05:39 PM.

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112
    Use 'code' tags, or 'php' tags so that your XML is displayed.

    The forum sticky has a link on how to use those tags.

    I tend to use childNodes to access stuff... it's different than firstChild and nextSibling

    myxml.firstChild.nextSibling

    is the same thing as

    myxml.childNodes[1]

    Sorry for the late response - been busy.
    Richard Lyman
    rich at lithinos.com
    www.lithinos.com

  3. #3
    Member
    Join Date
    Jul 2000
    Posts
    90
    no problem. Always grateful for a relpy, regardless.

    I've since found out what the problem was, and I'll mention it briefly for the benefit of anyone else searching through threads for help....

    In my case I'd created an element node called <xml> by mistake. I actually meant to type an XML declaration instead, so I had given myself an extra level to path down to!

    I'm now using the array-style syntax like you suggest which is so much easier, and still ignoring whitespace by checking for valid nodeNames in my loops whilst ignoring all other nodes.

    Cheers vaykent.

    FB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center