?
Solved

Simple xml example

Posted on 2004-09-26
7
Medium Priority
?
215 Views
Last Modified: 2010-04-03
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!
0
Comment
Question by:gmailrules
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:hsmtp
ID: 12156757
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.
0
 
LVL 6

Expert Comment

by:nishasrilankan
ID: 12157518
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"]
0
 
LVL 1

Author Comment

by:gmailrules
ID: 12166494
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]);
            }
      }
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
hsmtp earned 2000 total points
ID: 12167663
Here it is:

XML.prototype.ignoreWhite = true;
student = 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[0].firstChild.nodeValue, students.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue];
                  trace(student[i][0]+": "+student[i][1]);
            }
      }
};
0
 
LVL 1

Author Comment

by:gmailrules
ID: 12169646
It's not working, I still get undefined.  Any Ideas?
0
 
LVL 6

Expert Comment

by:hsmtp
ID: 12169686
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>
0
 
LVL 1

Author Comment

by:gmailrules
ID: 12174398
thanks :D
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question