Problem parsing XML using e4X & Flex 3 -
I have difficultly parsed the XML file using e4X. I can get information from the 'Version' tag, but I can not do with a nested tag.
Does anyone please tell me what I am doing?
Here's the XML:
& lt; NameFormat xmlns = "http://www.theaddress.com/file" & gt; & Lt; Version & gt; 1.0 & lt; / Edition & gt; & Lt; NameOfChild1 & gt; & Lt; NameOfChild2 & gt; & Lt; GeneralData & gt; & Lt; Identifier & gt; 2678 & lt; / Identifier & gt; & Lt; / GeneralData & gt; & Lt; / NameOfChild2 & gt; & Lt; / NameOfChild1 & gt; & Lt; / NameOfRoot & gt;
Here is the code:
& lt; Mx: HTTPService id = "MyService" url = "data.xml" result = "result handler (event)" as a result = "e4x" /> Private Function Results Handler (Event: ResultEvent): Zero {XMLData = event.result as XML; View Var: string = XMLData * :: Edition; // ver = 1.0 var id: string = XMLData. * :: NameOfChild1.NameofChild2.GeneralData.Identifier; // empty string}
Each element is named in your default namespace, So you need to be able to qualify each level:
var id: string = XMLData * :: NameOfChild1. * :: NameOfChild2. * :: general data. * :: Identifier; // or var n: namespaces = XMLData.namespace (); Var id: string = XMLData.n :: NameOfChild.n :: NameOfChild2.n :: GeneralData.n :: Identifier;
You can set a default namespace with the "Default XML namespace" directive:
default xml namespace = new namespace ("http: // Www. Theaddress.com/file "); Var id: string = xml.NameOfChild1.NameOfChild2.GeneralData.Identifier;
Comments
Post a Comment