Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

15. Working with Services and Server-Sid... > 15.20. Encode an ActionScript Data O...

15.20. Encode an ActionScript Data Object as XML

Problem

You need to convert an ActionScript object into XML.

Solution

Use the SimpleXMLEncoder.encodeValue() method to write an object and all of its properties to a XMLDocument.

Discussion

The SimpleXMLEncoder object is very useful when creating XML to send to a web service or to the URL of a server-side method that expects XML. The SimpleXMLEncoder object defines an encodeValue() method with the following signature:

encodeValue(obj:Object, qname:QName, parentNode:XMLNode):XMLNode

This method requires that the legacy XMLDocument object have the generated XML attached to it, so the generated XML is not only returned by the method, but also attached to the XMLNode within the XMLDocument object to which the parentNode is attached. After the XMLDocument has been generated, it can be converted to a XML object by calling the constructor of the XML object and passing the document as an argument to the constructor:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint