XML deserialization in actionscript



I am making an adobe premiere cc extension in actionscript3, which loads a XML file from File Dialog.


And I want to deserialize that XML file into my custom object, using SimpleXMLDecoder



// loads the data from the input XML file chosen by File Dialog
var xmlDoc:XMLDocument = new XMLDocument(loadFile.data.toString());
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
//Decode the input file
var data:Object = decoder.decodeXML(xmlDoc); (1)


I have a small test xml file:



<?xml version="1.0" encoding="utf-8"?>
<P>
<Data> (first data)
<Name>Video1</Name>
<Duration>250</Duration>
<FPS>24</FPS>
<Files>
<CFile>
<FileName>file 1</FileName>
<Meta>1</Meta>
</CFile>
</Files>
</Data>
<Data> (second data)
<Name>Video2</Name>
<Duration>250</Duration>
<FPS>24</FPS>
<Files>
<CFile>
<FileName>file 2</FileName>
<Meta>2</Meta>
</CFile>
<CFile>
<FileName>file 22</FileName>
<Meta>22</Meta>
</CFile>
<CFile>
<FileName>file 222</FileName>
<Meta>222</Meta>
</CFile>
</Files>
</Data>
<Data> (third data)
<Name>Video3</Name>
<Duration>250</Duration>
<FPS>24</FPS>
<Files/>
</Data>
</P>


Then i am trying to cast decoded object (1) of type OBJECTPROXY to my custom defined object.


I cant find how to cast automatically so i am trying with a manual foreach iteration through the elements of the decoded object, and putting it into the desired custom defined object.


The problem is: when FILES tag in the XML file contains just one CFILE (like the first DATA in the XML) that tag is converted to OBJECTPROXY type, but when FILES tag contains more than one CFILE(like second DATA element in the XML) the tag is converted to ARRAY COLLECTION type, and at the end i can't iterate through the tags because of type inconsistency.


Any help for this particular problem or for XML serialization in actionscript3 in general???


Thanks in advance.


No comments:

Post a Comment