Jump to content

reading in XML


dnainby
 Share

Recommended Posts

Hello, I'm trying to retreive information from an XML file, ie read in text displayed in an XML file. The code I'm using to read in the file is as follows:var xml_step_DocLoad:XML = new XML();xml_step_DocLoad.load("someText.xml");xml_step_DocLoad.onLoad = function(success) { var stepChildNodes=xml_step_DocLoad.childNodes[1].childNodes; };Here is the XML file:<textblock><step id="3" text="Step 1 text goes here"></step><step id="3" text="Step 2 text goes here"></step><step id="3" text="Step 3 text goes here"></step> <step id="4" text="Step 1 text goes here"></step><step id="4" text="Step 2 text goes here"></step> <step id="5" text="Step 1 text goes here"></step><step id="5" text="Step 2 text goes here"></step><step id="5" text="Step 2 text goes here"></step></textblock>What I need to do is get two bits of information, 'id' and 'text'. I can do this in JavaScript but i'm struggling with actionscript.Any ideas would be greatly received - thanksDan

Link to comment
Share on other sites

Try something like this

var xml_step_DocLoad:XML = new XML();xml_step_DocLoad.load("someText.xml");xml_step_DocLoad.onLoad = function(success){ var first_id = xml_step_DocLoad.childNodes[0].childNodes[0].attributes.id;var first_text = xml_step_DocLoad.childNodes[0].childNodes[0].attributes.text;};

Basically, after accessing whichever child node you want, just make sure you use the .attributes.attribute_you_want_to_get.. The code above should return the first id attribute of your step elements and the first text attirbute of your step element. Since I'm only looking at the first child of the first element in the XML document, the childNodes arrays are all set to 0. I might be wrong, but I'm pretty sure AS is similar to how you do it in JS. Check here for more help if need be. http://www.adobe.com/support/flash/action_...tionary829.html

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...