<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Converting objects to XML packets using the SimpleXMLEncoder class in Flex</title>
	<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Fri, 05 Dec 2008 01:05:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-16302</link>
		<author>peterd</author>
		<pubDate>Mon, 20 Oct 2008 14:20:31 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-16302</guid>
		<description>Paul B. Hartzog,

Correct, it doesn't look like I use the XMLNode reference returned by the &lt;code&gt;simpleXMLEncoder.encodeValue()&lt;/code&gt; method.
I haven't looked at this code in a long time, but here's what I think is happening:
1) The first line creates a new XMLDocument object.
2) The second line creates a new SimpleXMLEncoder object and passes the XMLDocument object created in on the first line. I believe the SimpleXMLEncoder constructor sets the empty XMLDocument object as the root XML node.
3) The third line calls calls the &lt;code&gt;encodeValue()&lt;/code&gt; method on the SimpleXMLEncoder object which "encodes an ActionScript object to XML using default serialization". According to the comments in the source code, the first parameter (&lt;code&gt;obj&lt;/code&gt;) is "the ActionScript object to encode", the second parameter (&lt;code&gt;qName&lt;/code&gt;) is "the qualified name of the child node", and the third parameter (&lt;code&gt;xmlDocument&lt;/code&gt;) is "an XMLNode under which to put the encoded value".
4) The fourth line converts the XMLDocument object to an XML object.

So, if you only used the first and last line, you'd always have an empty XML object. The second line creates a SimpleXMLEncoder instance which gets used in the third line to covert the specified Object and insert it into the &lt;code&gt;xmlDocument&lt;/code&gt; instance. I'm guessing the magic that is happening is that the SimpleXMLEncoder is directly modifying the XMLDocument object, which is why I didn't need to use the returned XMLNode object from line 3.

If you want to see exactly what happens in the SimpleXMLEncoder class, you can check out the source code in the installed SDKs /frameworks/projects/rpc/src/mx/rpc/xml/SimpleXMLEncoder.as file.

Peter</description>
		<content:encoded><![CDATA[<p>Paul B. Hartzog,</p>
<p>Correct, it doesn&#8217;t look like I use the XMLNode reference returned by the <code>simpleXMLEncoder.encodeValue()</code> method.<br />
I haven&#8217;t looked at this code in a long time, but here&#8217;s what I think is happening:<br />
1) The first line creates a new XMLDocument object.<br />
2) The second line creates a new SimpleXMLEncoder object and passes the XMLDocument object created in on the first line. I believe the SimpleXMLEncoder constructor sets the empty XMLDocument object as the root XML node.<br />
3) The third line calls calls the <code>encodeValue()</code> method on the SimpleXMLEncoder object which &#8220;encodes an ActionScript object to XML using default serialization&#8221;. According to the comments in the source code, the first parameter (<code>obj</code>) is &#8220;the ActionScript object to encode&#8221;, the second parameter (<code>qName</code>) is &#8220;the qualified name of the child node&#8221;, and the third parameter (<code>xmlDocument</code>) is &#8220;an XMLNode under which to put the encoded value&#8221;.<br />
4) The fourth line converts the XMLDocument object to an XML object.</p>
<p>So, if you only used the first and last line, you&#8217;d always have an empty XML object. The second line creates a SimpleXMLEncoder instance which gets used in the third line to covert the specified Object and insert it into the <code>xmlDocument</code> instance. I&#8217;m guessing the magic that is happening is that the SimpleXMLEncoder is directly modifying the XMLDocument object, which is why I didn&#8217;t need to use the returned XMLNode object from line 3.</p>
<p>If you want to see exactly what happens in the SimpleXMLEncoder class, you can check out the source code in the installed SDKs /frameworks/projects/rpc/src/mx/rpc/xml/SimpleXMLEncoder.as file.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul B. Hartzog</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-16293</link>
		<author>Paul B. Hartzog</author>
		<pubDate>Mon, 20 Oct 2008 05:46:34 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-16293</guid>
		<description>Great blog, and the code above works great as is, but 
I'm clearly missing something here:

&lt;pre class="code"&gt;
var xmlDocument:XMLDocument = new XMLDocument();
var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
var xml:XML = new XML(xmlDocument.toString());
&lt;/pre&gt;

xmlDocument is in the first line, and gets referred to in the last line, but the objects simpleXMLEncoder and xmlNode do not get used.  Why not simply use the first line and the last line?  What additional work is happening in the middle two lines?</description>
		<content:encoded><![CDATA[<p>Great blog, and the code above works great as is, but<br />
I&#8217;m clearly missing something here:</p>
<pre class="code">
var xmlDocument:XMLDocument = new XMLDocument();
var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
var xml:XML = new XML(xmlDocument.toString());
</pre>
<p>xmlDocument is in the first line, and gets referred to in the last line, but the objects simpleXMLEncoder and xmlNode do not get used.  Why not simply use the first line and the last line?  What additional work is happening in the middle two lines?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith H</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15956</link>
		<author>Keith H</author>
		<pubDate>Tue, 30 Sep 2008 20:33:30 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15956</guid>
		<description>Thanks Peter.  Will do...
Once again, great blog and your snippets have saves me more than once.</description>
		<content:encoded><![CDATA[<p>Thanks Peter.  Will do&#8230;<br />
Once again, great blog and your snippets have saves me more than once.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15939</link>
		<author>peterd</author>
		<pubDate>Mon, 29 Sep 2008 18:58:14 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15939</guid>
		<description>Keith H,

Thanks. You can file Flex bugs/enhancement requests at: http://bugs.adobe.com/flex/
If you post the bug number here, perhaps a few of us can subscribe and/or vote on the issue.

Peter</description>
		<content:encoded><![CDATA[<p>Keith H,</p>
<p>Thanks. You can file Flex bugs/enhancement requests at: <a href="http://bugs.adobe.com/flex/" rel="nofollow">http://bugs.adobe.com/flex/</a><br />
If you post the bug number here, perhaps a few of us can subscribe and/or vote on the issue.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith H</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15938</link>
		<author>Keith H</author>
		<pubDate>Mon, 29 Sep 2008 18:09:42 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15938</guid>
		<description>I came up with a nasty workaround here....but it works.
I created a non-framework copy of the SimpleXMLEncoder, renamed it and changed all the internal references.  I change the conditional on or around line 151 to the following....

I am thinking this is a bug and I will attempt to submit to Adobe.

&lt;pre class="code"&gt;
    else if (typeType == CustomXMLEncoder.ARRAY_TYPE) {
        var numMembers:uint = obj.length;
        // var itemQName:QName = new QName("", "item");

        for (var i:uint = 0; i  0) {
            var className:String = classNameArray[classNameArray.length -1];
            itemQName = new QName("", className.toLowerCase());
        }
        else itemQName = new QName("", "item");

        encodeValue(obj[i], itemQName, myElement);
    }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I came up with a nasty workaround here&#8230;.but it works.<br />
I created a non-framework copy of the SimpleXMLEncoder, renamed it and changed all the internal references.  I change the conditional on or around line 151 to the following&#8230;.</p>
<p>I am thinking this is a bug and I will attempt to submit to Adobe.</p>
<pre class="code">
    else if (typeType == CustomXMLEncoder.ARRAY_TYPE) {
        var numMembers:uint = obj.length;
        // var itemQName:QName = new QName("", "item");

        for (var i:uint = 0; i  0) {
            var className:String = classNameArray[classNameArray.length -1];
            itemQName = new QName("", className.toLowerCase());
        }
        else itemQName = new QName("", "item");

        encodeValue(obj[i], itemQName, myElement);
    }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith H</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15869</link>
		<author>Keith H</author>
		<pubDate>Fri, 26 Sep 2008 17:00:29 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15869</guid>
		<description>First off your blog rocks and it is the Flex bible as far as I am concerned.

I am using the SimpleXMLEncoder class to covert objects to XML.  All is well except when dealing with types Array Collections.

If I have an array of objects who themselves have their own types, the XML that the encoder generates refers to them as items, not the type of the object within the array.  Here is an example.
Here is what I want....
&lt;pre class="code"&gt;
&#60;campuses&#62;
&#60;campuse_choice&#62;
     properties here......
&#60;/campuse_choice&#62;
&#60;/campuses&#62;
&lt;/pre&gt;

What i get is.....
&lt;pre class="code"&gt;
&#60;campuses&#62;
     &#60;list&#62;
       &#60;source&#62;
           &#60;item&#62;
           &#60;/item&#62;
       &#60;/source&#62;
     &#60;/list&#62;
&#60;/campuses&#62;
&lt;/pre&gt;

I looked in the SimpleXMLEncoder class and I see the line (152) that converts them to items.  any way to have it pick up the object types within the ArrayCollection?</description>
		<content:encoded><![CDATA[<p>First off your blog rocks and it is the Flex bible as far as I am concerned.</p>
<p>I am using the SimpleXMLEncoder class to covert objects to XML.  All is well except when dealing with types Array Collections.</p>
<p>If I have an array of objects who themselves have their own types, the XML that the encoder generates refers to them as items, not the type of the object within the array.  Here is an example.<br />
Here is what I want&#8230;.</p>
<pre class="code">
&lt;campuses&gt;
&lt;campuse_choice&gt;
     properties here......
&lt;/campuse_choice&gt;
&lt;/campuses&gt;
</pre>
<p>What i get is&#8230;..</p>
<pre class="code">
&lt;campuses&gt;
     &lt;list&gt;
       &lt;source&gt;
           &lt;item&gt;
           &lt;/item&gt;
       &lt;/source&gt;
     &lt;/list&gt;
&lt;/campuses&gt;
</pre>
<p>I looked in the SimpleXMLEncoder class and I see the line (152) that converts them to items.  any way to have it pick up the object types within the ArrayCollection?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15425</link>
		<author>andrew</author>
		<pubDate>Tue, 09 Sep 2008 19:58:03 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15425</guid>
		<description>one small question:

The above example that I gave will output 




1.A
1.B





What's up with the double item? How can this be removed?

Andrew.</description>
		<content:encoded><![CDATA[<p>one small question:</p>
<p>The above example that I gave will output </p>
<p>1.A<br />
1.B</p>
<p>What&#8217;s up with the double item? How can this be removed?</p>
<p>Andrew.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15418</link>
		<author>andrew</author>
		<pubDate>Tue, 09 Sep 2008 14:43:46 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15418</guid>
		<description>Well, I found my solution.

...this worked for me:

arrColl[i]=[
	{
	c1: "1.A",
	c2: "1.B"
	}
	];</description>
		<content:encoded><![CDATA[<p>Well, I found my solution.</p>
<p>&#8230;this worked for me:</p>
<p>arrColl[i]=[<br />
	{<br />
	c1: &#8220;1.A&#8221;,<br />
	c2: &#8220;1.B&#8221;<br />
	}<br />
	];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andrew</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15417</link>
		<author>andrew</author>
		<pubDate>Tue, 09 Sep 2008 13:54:45 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-15417</guid>
		<description>What about if we have a multidimensional array created from Actionscript? 

How would we provide titles inside the Array (similar to your mx:object c="?") so it doesn't simple output "item" for each XML tag.

Thanks again for the great example.</description>
		<content:encoded><![CDATA[<p>What about if we have a multidimensional array created from Actionscript? </p>
<p>How would we provide titles inside the Array (similar to your mx:object c=&#8221;?&#8221;) so it doesn&#8217;t simple output &#8220;item&#8221; for each XML tag.</p>
<p>Thanks again for the great example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-12853</link>
		<author>peterd</author>
		<pubDate>Thu, 22 May 2008 01:55:28 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-12853</guid>
		<description>&lt;a href="http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-12849" rel="nofollow"&gt;Guido Sarduchi&lt;/a&gt;,

Can you please log a bug with a simple, reproducible test case at http://bugs.adobe.com/flex/.

Also, if you post the bug number here, I can vote on the issue and subscribe.

Thanks,
Peter</description>
		<content:encoded><![CDATA[<p><a href="http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comment-12849" rel="nofollow">Guido Sarduchi</a>,</p>
<p>Can you please log a bug with a simple, reproducible test case at <a href="http://bugs.adobe.com/flex/." rel="nofollow">http://bugs.adobe.com/flex/.</a></p>
<p>Also, if you post the bug number here, I can vote on the issue and subscribe.</p>
<p>Thanks,<br />
Peter</p>
]]></content:encoded>
	</item>
</channel>
</rss>
