A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Reading XML

Hybrid View

  1. #1
    Junior Member
    Join Date
    Apr 2001
    Posts
    8

    Lightbulb

    I'm trying to read an XML document with this structure
    Code:
    substitute the * with < and > (case you hadn't figured that one out yet ;-)
    *? xml etc*
      *list*
        *member*
          *id*12345*/id*
          *name*John Doe*/name*
        */member*
      */list*
    (btw why won't the post display my tags when I use < >?)

    but what 's the correct syntax (using the xml object) to read this? I've gotten so far as to declare the XML object, and have it call a function when onLoad. The function itself:

    member = myXML.firstChild.firstChild;
    id = member.firstChild;
    name = id.nextSibling;
    var1 = name.toString();

    which puts "*name*John Doe*/name*" in my variable - what am I doing wrong ?

    JJ

  2. #2
    Junior Member
    Join Date
    Apr 2001
    Posts
    4
    Im pretty new to XML myself, but have you tried

    *member*
    *member id = "1234"
    name = "john doe"/*

    *member id = "3456"
    name = "fred smith"/*
    */member*

    hope it helps

    Andy




  3. #3
    Junior Member
    Join Date
    Apr 2001
    Posts
    8

    OK but not what I really want ...

    Originally posted by andyj
    Im pretty new to XML myself, but have you tried

    *member*
    *member id = "1234"
    name = "john doe"/*

    *member id = "3456"
    name = "fred smith"/*
    */member*

    hope it helps

    Andy



    Ok I admit using attributes is easier, but I don't want to (some of the data wouldn't be suitable to be used as attributes).

    Jef

  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    if you change your xml document to look like this:

    Code:
    &lt;list&gt;&lt;member&gt;&lt;id&gt;12345&lt;/id&gt;&lt;name&gt;John Doe&lt;/name&gt;&lt;/member&gt;&lt;/list&gt;
    (basically i removed the xml declaration tag, which isnt required)

    You can use this code to grab the name and id:

    Code:
    myxml=new XML()
    myxml.load("yourxmlfile.xml")
    myxml.onLoad=parse
    
    function parse(loaded){
        if(loaded){
    id=myxml.firstChild.firstChild.firstChild.firstChild.nodeValue
    name=myxml.firstChild.firstChild.firstChild.nextSibling.firstChild.nodeValue
    }
    }

  5. #5
    Junior Member
    Join Date
    Mar 2001
    Posts
    3
    Originally posted by FlashGuru
    if you change your xml document to look like this:

    Code:
    <list><member><id>12345</id><name>John Doe</name></member></list>
    (basically i removed the xml declaration tag, which isnt required)

    You can use this code to grab the name and id:

    Code:
    myxml=new XML()
    myxml.load("yourxmlfile.xml")
    myxml.onLoad=parse
    
    function parse(loaded){
        if(loaded){
    id=myxml.firstChild.firstChild.firstChild.firstChild.nodeValue
    name=myxml.firstChild.firstChild.firstChild.nextSibling.firstChild.nodeValue
    }
    }
    Ok, I'm sorry to open this thread again,
    but .... what I don't understand is this: id=myxml.firstChild.firstChild.firstChild.firstChi ld

    4 X firstChild ??

    Perhaps you're willing to explain to me what the very first firstChildNode is ?

  6. #6
    Junior Member
    Join Date
    Mar 2001
    Posts
    3

    Lightbulb

    Ah, ok, got it now (finally)

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