Link to home
Start Free TrialLog in
Avatar of gmailrules
gmailrules

asked on

Simple xml example

I would like a simple example on how to take data from an xml document and put it in flash.

so for example:

<student>
      <name>gmailrules</name>
      <age>99</age>
</student>

<student>
      <name>yourule</name>
      <age>99</age>
</student>

when parsed in flash would create 'student' arrays with both containing variables named 'name' and 'age'
 
Maybe there would be a better way to store it? such as one array with two arrays in it?  Well any help would be aprecciated.  thanks!
Avatar of hsmtp
hsmtp

Take a look here:
http://www.macromedia.com/support/flash/applications/jpeg_slideshow_xml/jpeg_slideshow_xml06.html

Macromedia has a lot of good examples of using XML.
you'll have to use multidimensional array...

bothArrays = new Array();
students = new XML();
students.onLoad = function(success){
if(success){

for(i=0;i<students.firstChild.childNodes.length){
student[i] = [students.firstChild.childNodes[i].childNodes[i].nodeValue  ,   students.firstChild.childNodes[i].childNodes[i+1].nodeValue];
}
}
}

//Eg: student[0] = ["gmailrules","99"]
student[1] = ["yourule","99"]
Avatar of gmailrules

ASKER

it doesn't work.  I just get undefined

XML.prototype.ignoreWhite = true;
bothArrays = new Array();
students = new XML();
students.load("students.xml");
students.onLoad = function(success)
{
      if(success)
      {
            for(i=0;i<students.firstChild.childNodes.length; i++)
            {
                  student[i] = [students.firstChild.childNodes[i].childNodes[i].nodeValue  ,   students.firstChild.childNodes[i+1].childNodes[i].nodeValue];
                  trace (student[i]);
            }
      }
}
ASKER CERTIFIED SOLUTION
Avatar of hsmtp
hsmtp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's not working, I still get undefined.  Any Ideas?
The XML structure in students.xml is following:

<students>
      <student>
              <name>gmailrules</name>
              <age>99</age>
      </student>
      
      <student>
              <name>yourule</name>
              <age>99</age>
      </student>
</students>
thanks :D