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!
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!
you'll have to use multidimensional array...
bothArrays = new Array();
students = new XML();
students.onLoad = function(success){
if(success){
for(i=0;i<students.firstCh ild.childN odes.lengt h){
student[i] = [students.firstChild.child Nodes[i].c hildNodes[ i].nodeVal ue , students.firstChild.childN odes[i].ch ildNodes[i +1].nodeVa lue];
}
}
}
//Eg: student[0] = ["gmailrules","99"]
student[1] = ["yourule","99"]
bothArrays = new Array();
students = new XML();
students.onLoad = function(success){
if(success){
for(i=0;i<students.firstCh
student[i] = [students.firstChild.child
}
}
}
//Eg: student[0] = ["gmailrules","99"]
student[1] = ["yourule","99"]
ASKER
it doesn't work. I just get undefined
XML.prototype.ignoreWhite = true;
bothArrays = new Array();
students = new XML();
students.load("students.xm l");
students.onLoad = function(success)
{
if(success)
{
for(i=0;i<students.firstCh ild.childN odes.lengt h; i++)
{
student[i] = [students.firstChild.child Nodes[i].c hildNodes[ i].nodeVal ue , students.firstChild.childN odes[i+1]. childNodes [i].nodeVa lue];
trace (student[i]);
}
}
}
XML.prototype.ignoreWhite = true;
bothArrays = new Array();
students = new XML();
students.load("students.xm
students.onLoad = function(success)
{
if(success)
{
for(i=0;i<students.firstCh
{
student[i] = [students.firstChild.child
trace (student[i]);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>
<students>
<student>
<name>gmailrules</name>
<age>99</age>
</student>
<student>
<name>yourule</name>
<age>99</age>
</student>
</students>
ASKER
thanks :D
http://www.macromedia.com/support/flash/applications/jpeg_slideshow_xml/jpeg_slideshow_xml06.html
Macromedia has a lot of good examples of using XML.