Solved

Simple xml example

Posted on 2004-09-26
7
205 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 6

Accepted Solution

by:
hsmtp earned 500 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download slideshow or picture elements 16 437
Accessing Live Dynamic Stream 6 197
Converting CFGRID from Flash to HTML in Coldfusion 1 96
free photo watermark software 5 84
This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

773 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