Hello I am trying to trace some XML Data. I used a URLLoader and once load is complete, I try to trace back the XML Data. I can trace the entire file
trace(xmlData);
but if I try to trace a specific node, I get nothing in my trace
trace(xmlData.captions);
What could I be doing wrong? All tutorials I've seen make this seem so straight forward, but开发者_如何学Python it's just not working for me?
//////EDIT////
here is the question clarified.
protected var xmlLoader:URLLoader = new URLLoader();
public var xmlData:XML = new XML();
public function loadXML(_filename:String) {
xmlLoader.addEventListener(Event.COMPLETE, loadIt);
xmlLoader.load(new URLRequest(_filename));
}
function loadIt(e:Event):void {
xmlData = new XML(e.target.data);
parseData(xmlData);
}
function parseData(input:XML):void {
trace(xmlData.captions);
}
If I just do trace(xmlData); I see everything fine. It's when I add the .captions that I get a blank trace.
here is my XML file
<?xml version="1.0" encoding="utf-8"?>
<captions>
<cap start="00:01.7">
Narrator: Someone watching a car
<br/>
accelerate toward light speed
</cap>
<cap start="00:05.0">
would see something
<br/>
very strange.
</cap>
</captions>
It's because <captions>
is your so called root node. So when you try parsing input.captions
you actually search for captions.captions
. Parsing the children of your root node can be done similar to what you've already tried:
function parseData(input:XML):void
{
// xml list of your cap attributes
trace(input.cap);
for (var i : int = 0; i < input.children().length(); i++)
{
// every child node within your captions root node
trace(input.children()[i]);
}
}
As @rvmool said, captions
is the root node so it does not exist in the XML object.
Plus, don't forget to use toXMLString()
when you wish to trace an XML's content.
trace(xmlData.cap.toXMLString());
精彩评论