Solved

Simple xml example

Posted on 2004-09-26
7
202 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Accepted Solution

by:
hsmtp earned 500 total points
Comment Utility
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
Comment Utility
It's not working, I still get undefined.  Any Ideas?
0
 
LVL 6

Expert Comment

by:hsmtp
Comment Utility
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
Comment Utility
thanks :D
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now