Convert ArrayCollection or Object to XML


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.