Flex XML dynamic type -
I have an application that receives dynamic XML data from the server XML structure is dynamic and tags / attributes are named Can not be predicted. Any line item can be hardcoded data is coming back from a database (imagine columns and rows), and the data type is known on server side. The following is just one example, only shows the structure of how data comes back.
& lt; Dataset & gt; & Lt; Line & gt; & Lt; First name value = "Chris" type = "string" /> & Lt; LastName value = "MacDonald" type = "string" /> & Lt; Age value = "24" type = "integer" /> & Lt; / Row & gt; & Lt; Line & gt; & Lt; First name value = "bob" type = "string" /> & Lt; LastName value = "boron" type = "string" /> & Lt; Age value = "43" type = "integer" /> & Lt; / Row & gt; & Lt; / Dataset & gt;
I'm wondering how / if I can type that data into an array combination:
public var arr: ArrayCollection = New ArrayCollection [First name: "Chris", last name: "McDonald", Age: 24], ...); // Note that age is an integer, string is not
thanks in advance
Yes, I think you can do this to see if it helps:
public function parseXML (datasetXML: string): ArrayCollection {var a: Array = new Array () ; Var xml: XML = New XML (Dataset XML); Xml.ignoreWhitespace = True; Var rows: XMLList = xml.row; For each (different rows in rows) {a.push (getObject (line)); }} Public function getObject (xml: XML): object {var obj: object = new object (); Xml.elements () in each (varml) {if (column. Type == "string") {obj [column.localName (=)] = column @ Value; } And if (column. @ Type = "integer") {obj [column.localName ()] = int (column. @ Value); }} Return obj; }
Comments
Post a Comment