dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Loading xml data into arrays - Please help

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    10

    Loading xml data into arrays - Please help

    Hi I have been trying for the last two days to make these arrays so that I can manipulae the data.

    The file loads fine and I can load the different ellements into a text field.

    there are many courses element - below is an example of one

    I think I need a recursive function but I can not get it to work. Help please

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <coursesSummary>
    <courses>
    <year>2009</year>
    <quarter>1</quarter>
    <region>Central Courses</region>
    <coursecode>3634500</coursecode>
    <coursetitle>Great course</coursetitle>
    <coursesrun>1</coursesrun>
    <maxplaces>10</maxplaces>
    <numberattended>9</numberattended>
    <splitbyregion>no</splitbyregion>
    <centralreport>yes</centralreport>
    </courses>
    //courses elements are are repeated here
    </coursesSummary>

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    for brevity i have snipped the xml file -
    PHP Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <coursesSummary>

    <courses>
    <year>2006</year>
    <quarter>1</quarter>
    <region>North Courses</region>
    </courses>

    <courses>
    <year>2007</year>
    <quarter>2</quarter>
    <region>South Courses</region>
    </courses>

    <courses>
    <year>2008</year>
    <quarter>3</quarter>
    <region>East Courses</region>
    </courses>

    <courses>
    <year>2009</year>
    <quarter>4</quarter>
    <region>West Courses</region>
    </courses>

    </coursesSummary>
    in Flash (AS2), cycle thro the nodes, adding their node value to an associative array
    PHP Code:
    _xml = new XML();
    _xml.ignoreWhite true;
    _xml.load("courses.xml");

    arr = [];

    _xml.onLoad = function(){ 
    cNodes this.firstChild.childNodes
    len cNodes.length
    for(var 
    n:Number=0;n!=len;n++){ 
    obj = new Object(); 
    obj.yr cNodes[n].childNodes[0].firstChild.nodeValue
    obj.qtr cNodes[n].childNodes[1].firstChild.nodeValue;
    obj.reg cNodes[n].childNodes[2].firstChild.nodeValue
    arr[n] = obj;

    }; 

    /* produces this associative array -

    _level0.arr = [object #2, class 'Array'] [
        0:[object #3, class 'Object'] {
          yr:"2006",
          qtr:"1",
          reg:"North Courses"
        },
        1:[object #4, class 'Object'] {
          yr:"2007",
          qtr:"2",
          reg:"South Courses"
        },
        2:[object #5, class 'Object'] {
          yr:"2008",
          qtr:"3",
          reg:"East Courses"
        },
        3:[object #6, class 'Object'] {
          yr:"2009",
          qtr:"4",
          reg:"West Courses"
        }
      ]

    to output the 4th quarter region -  trace(arr[3].reg); - */ 
    hth

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    10
    Thanks that looks just the thing.

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