dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Reading the XML childNodes from Flash...

  1. #1
    Member
    Join Date
    Nov 2000
    Posts
    53
    Hi,

    Can somebody give me a 'clear' explanation of reading 'this' XML file;

    <TUTOR>
    <RECORD>
    <FIELD>
    <VALUE>400</VALUE>
    </FIELD>
    </RECORD>
    <RECORD>
    <FIELD>
    <VALUE>900</VALUE>
    </FIELD>
    </RECORD>
    <RECORD>
    <FIELD>
    <VALUE>1000</VALUE>
    </FIELD>
    </RECORD>
    </TUTOR>

    from Flash and putting those data to variables in Flash like

    movienumber1=400
    movienumber2=900
    movienumber3=1000

    I am really confused because of the 'childNodes' numbers... I could not understand how the childNode numbers are increasing...

    Thank you...


  2. #2
    Member
    Join Date
    Nov 2000
    Posts
    53

    Oooops...

    Sorry XML file did not appear in the first post...

    < TUTOR >
    < RECORD >
    < FIELD >
    < VALUE >400< /VALUE >
    < /FIELD >
    < /RECORD >
    < RECORD >
    < FIELD >
    < VALUE >900< /VALUE >
    < /FIELD >
    < /RECORD >
    < RECORD >
    < FIELD >
    < VALUE >1000< /VALUE >
    < /FIELD>
    < /RECORD >
    < RECORD >
    < FIELD >
    < VALUE >1100< /VALUE >
    < /FIELD >
    < /RECORD >
    < RECORD >
    < FIELD >
    < VALUE >1200< /VALUE >
    < /FIELD >
    < /RECORD >
    < /TUTOR >

  3. #3
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Uhh...

    childNodes is an attribute. You can treat it just like an Array object.

    < top>< childNode0/>< childNode1/>< /top>

    But in your example XML you have it nested differently since you have several groups of childNodes...

    < top>< childNode0>< childNode0/>< /childNode0>< childNode1>< childNode0/>< /childNode1>< /top>

    Notice there are two childNode0's.. but -

    childNodes[0].childNodes[0]

    is different than -

    childNodes[1].childNodes[0]

    I hope that helped!

  4. #4
    Member
    Join Date
    Nov 2000
    Posts
    53

    Thank you for the reply...

    Thank you for your reply... Can you give me an example of converting those XML data to FLash variables like

    movienumber1=400
    movienumber2=900
    movienumber3=1000

    I really could not understand the logic of "for()" loop and Array in Flash...



  5. #5
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Uhh...

    Example...

    XML::

    < top>
    < inside1/>
    < inside2/>
    < inside3/>
    < /top>

    Stage setup::

    Dynamic text instances named - 'text1', 'text2', 'text3'...

    ActionScript... (assuming you've already browsed to the 'top' node.. that the 'top' node == currentNode)

    for(i=0;i<currentNode.childNodes.length;i++){
    _root["text"+i].text=currentNode.childNodes[ i].nodeName;
    }

    ((You'll have to forgive the space after the '[' before the 'i'.. the forum engine would parse it))

  6. #6
    Member
    Join Date
    Nov 2000
    Posts
    53

    Thank you...

    Thank you, I think I has been solved for this XML file

    < top>
    < value>100< /value>
    < value>200< /value>
    < value>300< /value>
    < value>400< /value>
    < value>500< /value>
    < value>600< /value>
    < value>700< /value>
    < value>800< /value>
    < /top>

    with these lines...

    function parseit(success) {
    if (success) {
    for (r=0; r < totalRecords; r++) {
    _root["results"+r] = searchresultsxml.childNodes[ 0].childNodes[ r].childNodes[ 0].nodeValue;
    }
    }
    }

    However still those "childNodes" are not so clear, but it works now...

    I have another question, how can I delete all of those variables? When the database get bigger the search results will get bigger and it will be problematic to delete the variables.. Another user had told me to create Arrays and delete them all with one command. Is it possible?




  7. #7
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Uhh...

    There is really no reason to take XML and place it in an Array. (I'll save the more scathing comments on this 'abuse' of XML for later )

    I'm confused as to how those 'childNodes' aren't so clear...

    Straight from the FMX reference -

    -START FROM THE REFERENCE SECTION-

    XML.childNodes

    Availability

    Flash Player 5.

    Usage

    myXML.childNodes

    Parameters

    None.

    Returns

    Nothing.

    Description

    Collection (read-only); returns an array of the specified XML object's children. Each element in the array is a reference to an XML object that represents a child node. This is a read-only property and cannot be used to manipulate child nodes. Use the methods appendChild, insertBefore, and removeNode to manipulate child nodes.

    This collection is undefined for text nodes (nodeType == 3).

    See also

    XML.nodeType

    -END FROM THE REFERENCE SECTION-

    Finally.. why do you need to delete the variables?? Flash has garbage collection of it's own... so now I'm confused!

  8. #8
    Member
    Join Date
    Nov 2000
    Posts
    53

    I am sure it is very clear for YOU... :)

    Thank you for your 'all' replies...

    First of all when English is not your mother tongue, those descriptions are not so easy to grasp. And secondly, when the issue is something you never heard before or never imagined, it is like describing the colors to a blind person. Since last week, I am writing to the forums to get a "clear" answer, but everbody approached the issue as if they were explaining to theirselves, not to a person who does not know a,b,c yet... :)

    And I could find a better explanation of the childNodes in Flash at;

    http://actionscript-toolbox.com/xmlobject.php

    and now it is "more" clear.... :)

    And when it comes to cleaning the variables, it is related to using those variables several times and when I do not clean them all they appear as a value somewhere in the movie when get a smaller amount of results from the later searches. But I used same method to make variables to clean all. And it works in a second perfectly...

    for (r=0; r < totalRecords; r++) {
    _root[ "results"+r ] = "";
    }

    (PS: For the other users there is no space before or after "<", "[" and "]")

    I think that is all for now. I believe I will have more questions soon, when I start to build the real project... :)

    Again, thank you for your patience and kind help..

    Regards...


  9. #9
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Uhh...

    Ahh.. I didn't know you weren't 'english'.. sorry!

    I'm glad you found answers to your questions, I'll keep that URL for others.

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