PDA

View Full Version : XMLList and xml tag references


nomaeswonk
02-16-2008, 07:03 AM
Here's what works:


xml = new XML(e.target.data);
trace(xml); // outputs: <images>
// <image>01.jpg</image>
// <image>02.jpg</image>
// </images>


Here's where it doesn't:


xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.images;
trace(il); // doesn't output anything


I thought it might be an error with my xml file, but it seems to load fine and it also tried this and it worked fine:


xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.children();
trace(il); // outputs: <image>01.jpg</image>
// <image>02.jpg</image>


Does anyone know what I am doing wrong in that second snippet of code? Could it still be a problem with the xml file?

sgartner
02-16-2008, 07:16 AM
Here's what works:


xml = new XML(e.target.data);
trace(xml); // outputs: <images>
// <image>01.jpg</image>
// <image>02.jpg</image>
// </images>


Here's where it doesn't:


xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.images;
trace(il); // doesn't output anything


I thought it might be an error with my xml file, but it seems to load fine and it also tried this and it worked fine:


xml = new XML(e.target.data);
trace(xml); // outputs same as above
var il:XMLList = xml.children();
trace(il); // outputs: <image>01.jpg</image>
// <image>02.jpg</image>


Does anyone know what I am doing wrong in that second snippet of code? Could it still be a problem with the xml file?

You're not doing anything wrong, but you're making an assumption that the variable "xml" is outside of the heirarchy. If you were to name that variable after the root node it would suddenly make more sense:


var images:XML = new XML(e.target.data);
trace(images); // outputs: <images>
// <image>01.jpg</image>
// <image>02.jpg</image>
// </images>

// The following no longer looks like it should work.
var il:XMLList = images.images;
trace(il); // doesn't output anything since there is no <images> within <images>

var il:XMLList = images.image;
trace(il); // outputs: <image>01.jpg</image>
// <image>02.jpg</image>



Hopefully this makes things clear. If not let me know and I'll try again.

nomaeswonk
02-16-2008, 03:20 PM
Beauty! I thought I had tried that, but obviously not. Thanks for the help!