A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] XML nodes problem

  1. #1

    resolved [RESOLVED] XML nodes problem

    This is pretty basic , and I've done this before but some now now it doesn't seem to be working....

    My xml looks like this :

    <thing>
    <title>blah </title>
    <colors>
    <color>red</color>
    <color>gold</color>
    <color>green</color>
    </colors>
    </thing>



    Actionscript Code:
    function ParseObject(printable:XML):void {
           
             
             //loop through all of the color child nodes.
                var colors:XMLList = printable.colors ;
                         
                for each(var node in colors){
                    trace ( node.childNodes); ///produces nothing.
                   
                    for (var i = 0; i < node.childNodes.length; i++){
                        trace (node.childNodes[i]) ;
                        trace("hey"); //produces nothing
                        }                
                    }


    colors is a valid xml object, when I trace (printable) I get the full xml tree in the console, and when I trace (colors) , I get the colors node. But it's not getting me each color.

    That's what I need. clearly I'm not extracting the child nodes properly......

    Any hints? I'm sure it's something obvious.
    -Nmuta

  2. #2
    Ok, had to dig through some old code but I resolved this.

    For anyone with the same question, here's the answer....

    to get the first child I can simply do

    colors.color[0]

    and to loop through all I can do

    for (var i=0 ; i< printable.colors.child("*").length(); i++) {
    -Nmuta

  3. #3
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    Actionscript Code:
    var xml:XML=new XML(
    <thing>
    <title>blah </title>
    <colors>
    <color>red</color>
    <color>gold</color>
    <color>green</color>
    </colors>
    </thing>);

    ParseObject(xml);

    function ParseObject(printable:XML):void {
        //loop through all of the color child nodes.
        var colors:XMLList = printable.colors;
        for each (var node in colors) {
            trace(node.children().length());
            var child=node.children();
            trace(child);///produces nothing.
            for (var i = 0; i <child.length(); i++) {
                trace(child[i]);
            }
        }
    }


    arkitx

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