I am having difficultly parsing an XML file using e4X. I can acquire information from the 'version' tag, but I cannot from any nested tags.
Could someone please point out what I am doing wrong?
Here is the XML:
<NameOfRoot xmlns="http://www.theaddress.com/file">
<version>1.0</version>
<NameOfChild1>
<NameOfChild2>
<GeneralData>
<Identifier>2678</Identifier>
</GeneralData>
</NameOfChild2>
</NameOfChild1>
</NameOfRoot>
Here is the code:
<mx:HTTPService id="MyService" url="data.xml" result="resultHandler(event)" resultFormat="e4x"/>
private function resultHandler(event:ResultEvent):void {
XMLData = event.result as XML;
var ver:String = XMLData.*::version; // ver = 1.0
var id:String = XMLData.*::NameOfChild1.NameofChild2.GeneralData.Identifier; //empty string
}
Each element is namespaced in your default namespace, so you need to qualify each level:
var id:String = XMLData.*::NameOfChild1.*::NameOfChild2.*::GeneralData.*::Identifier;
// or
var n:Namespace = XMLData.namespace();
var id:String = XMLData.n::NameOfChild.n::NameOfChild2.n::GeneralData.n::Identifier;
You can set a default namespace with a "default xml namespace" directive:
default xml namespace = new Namespace("http://www.theaddress.com/file");
var id:String = xml.NameOfChild1.NameOfChild2.GeneralData.Identifier;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.