A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: parsing xml into 3d array AS2

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    137

    parsing xml into 3d array AS2

    Hi i would like to know how to parse the following xml into a 3d array.
    The number of rLables is unsure. I would like the array to be
    3Darr[na][cm][mo]

    here is the xml and below is my attempt:
    Code:
    <rEnd>
            <Lables>
                <rLables names="name this" cMod="10" modname="a1"></rLables>
            </Lables>
            <Lables>
                <rLables names="name that" cMod="15" modname="aa1"></rLables>
            </Lables>
            <Lables>
                <rLables names="name A" cMod="10" modname="zz"></rLables>
            </Lables>
            <Lables>
                <rLables names="name 4" cMod="5" modname="mo7"></rLables>
            </Lables>
    </rEnd>
    Thanks.

    Code:
    3Darr:Array [];
    na:String, cm:Number, mo:String
    
    var rEnd= this.firstChild.childNodes; 
    
    for (var r=0; r<rEnd.length; r++){ 
      
    var Lables = rEnd[r]; 
    
      for (var s=0; s<rLables.length; s++){ 
       3Darr[na]=rLables.attributes.names;
       3Darr[cm]=rLables.attributes.cMod;
       3Darr[mo]=rLables.attributes.modname;
      } 
    }
    Last edited by havey; 09-23-2007 at 10:47 PM.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    _xml = new XML();
    _xml.ignoreWhite true;
    _xml.load("test.xml");

    _xml.onLoad = function(){
    aNode this.firstChild.childNodes
    len aNode.length;
    oArr = [];

    for (var 
    r=0r<lenr++){ 
    obj = {};
    obj.na aNode[r].firstChild.attributes['names'];
    obj.cm aNode[r].firstChild.attributes['cMod'];
    obj.mo aNode[r].firstChild.attributes['modname'];
    oArr[r] = obj;

    };

    /*-- code produces this array --
    oArr =  [
        0:[object #8, class 'Object'] {
          na:"name this",
          cm:"10",
          mo:"a1"
        },
        1:[object #9, class 'Object'] {
          na:"name that",
          cm:"15",
          mo:"aa1"
        },
        2:[object #10, class 'Object'] {
          na:"name A",
          cm:"10",
          mo:"zz"
        },
        3:[object #11, class 'Object'] {
          na:"name 4",
          cm:"5",
          mo:"mo7"
        }
      ]
    */ 
    does this help ??

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