Posted By

msdevweb on 03/03/11


Tagged

object xml conversion arrayCollection


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

scottwatkins


Convert ArrayCollection or Object to XML


 / Published in: ActionScript 3
 

  1. public static function objectToXML(obj:Object):XML {
  2. var qName:QName = new QName("root");
  3. var xmlDocument:XMLDocument = new XMLDocument();
  4. var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
  5. var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
  6. var xml:XML = new XML(xmlDocument.toString());
  7. return xml;
  8. }
  9. //or arraycollection:
  10.  
  11. public static function objectToXML(obj:ArrayCollection):XML {
  12. var qName:QName = new QName("root");
  13. var xmlDocument:XMLDocument = new XMLDocument();
  14. var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
  15. var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
  16. var xml:XML = new XML(xmlDocument.toString());
  17. return xml;
  18. }

Report this snippet  

You need to login to post a comment.