Solved

Simple xml example

Posted on 2004-09-26
7
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Action Script commands 3 223
Flash player plugin 13 7 347
ActionScript 3 - Removing Duplicates in ArrayCollection 1 418
Flash player 17 install script .bat or .vbs 9 578
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…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

733 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