Jump to content

reading in XML


dnainby

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...