<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; XMLDocument</title>
	<atom:link href="http://blog.flexexamples.com/category/xmldocument/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Parsing XML nodes and Objects with dashes in their names in ActionScript 3.0</title>
		<link>http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/</link>
		<comments>http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 08:12:49 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[SimpleXMLDecoder]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLDocument]]></category>
		<category><![CDATA[toXMLString()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/</guid>
		<description><![CDATA[<p>The following example shows how you can parse an XML node with a dash in its node name (&#60;font-family /&#62;) as well as parsing an Object with a dash in it&#8217;s identifier using the square bracket notation ([]).</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XML_parser_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/ --&#62; &#60;mx:Application [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can parse an XML node with a dash in its node name (&lt;font-family /&gt;) as well as parsing an Object with a dash in it&#8217;s identifier using the square bracket notation ([]).</p>
<p>Full code after the jump.</p>
<p><span id="more-776"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/XML_parser_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/ --&gt;
&lt;mx:Application name="XML_parser_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.rpc.xml.SimpleXMLDecoder;
            import mx.utils.ObjectUtil;

            private function init():void {
                var obj:Object = xmlToObject(xmlDP);

                txtXML.text = xmlDP.toXMLString();
                txtObject.text = ObjectUtil.toString(obj);

                lblXML.text = xmlDP.entry.child('font-family').text();
                lblObject.text = String(obj.root.entry["font-family"]);
            }

            private function xmlToObject(value:XML):Object {
                var xmlStr:String = value.toXMLString();
                var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
                var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                var resultObj:Object = decoder.decodeXML(xmlDoc);
                return resultObj;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:XML id="xmlDP"&gt;
        &lt;root&gt;
            &lt;entry&gt;
                &lt;font-family&gt;Arial&lt;/font-family&gt;
                &lt;font-size&gt;12&lt;/font-size&gt;
                &lt;font-weight&gt;normal&lt;/font-weight&gt;
                &lt;text-decoration&gt;underline&lt;/text-decoration&gt;
                &lt;text&gt;Hello world!&lt;/text&gt;
            &lt;/entry&gt;
        &lt;/root&gt;
    &lt;/mx:XML&gt;

    &lt;mx:Panel id="xmlPanel"&gt;
        &lt;mx:Text id="txtXML" /&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Label text="font-family:" /&gt;
            &lt;mx:Label id="lblXML" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

    &lt;mx:Panel id="objPanel" height="{xmlPanel.height}"&gt;
        &lt;mx:Text id="txtObject" /&gt;
        &lt;mx:ControlBar&gt;
            &lt;mx:Label text="font-family:" /&gt;
            &lt;mx:Label id="lblObject" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/XML_parser_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/XML_parser_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Parsing XML nodes and Objects with dashes in their names in ActionScript 3.0 on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/',contentID: 'post-776',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'toXMLString()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/08/28/parsing-xml-nodes-and-objects-with-dashes-in-their-names-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>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>
		<comments>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 06:23:58 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[QName]]></category>
		<category><![CDATA[SimpleXMLEncoder]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLDocument]]></category>
		<category><![CDATA[XMLNode]]></category>
		<category><![CDATA[encodeValue()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/</guid>
		<description><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/">&#8220;Converting XML to objects using the Flex SimpleXMLDecoder class&#8221;</a>, we saw how to convert an XML instance into an Object instance using the SimpleXMLDecoder class and decodeXML() method.</p> <p>The following example shows how you can convert an array of objects into an XML object using the SimpleXMLEncoder class and encodeValue() [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/">&#8220;Converting XML to objects using the Flex SimpleXMLDecoder class&#8221;</a>, we saw how to convert an XML instance into an Object instance using the SimpleXMLDecoder class and <code>decodeXML()</code> method.</p>
<p>The following example shows how you can convert an array of objects into an XML object using the SimpleXMLEncoder class and <code>encodeValue()</code> method in Flex.</p>
<p>Full code after the jump.</p>
<p><span id="more-543"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLEncoder_encodeValue_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:ArrayCollection id="arrColl"&gt;
        &lt;mx:source&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object c1="1.A" c2="1.B" /&gt;
                &lt;mx:Object c1="2.A" c2="2.B" /&gt;
                &lt;mx:Object c1="3.A" c2="3.B" /&gt;
                &lt;mx:Object c1="4.A" c2="4.B" /&gt;
                &lt;mx:Object c1="5.A" c2="5.B" /&gt;
                &lt;mx:Object c1="6.A" c2="6.B" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:source&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.rpc.xml.SimpleXMLEncoder;
            import mx.utils.ObjectUtil;

            private function init():void {
                var xml:XML = objectToXML(arrColl.source);
                textArea1.text = ObjectUtil.toString(arrColl.source);
                textArea2.text = xml.toXMLString();
            }

            private function objectToXML(obj:Object):XML {
                var qName:QName = new QName("root");
                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());
                // trace(xml.toXMLString());
                return xml;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:HDividedBox width="100%" height="100%"&gt;
        &lt;mx:TextArea id="textArea1"
                editable="false"
                width="100%"
                height="100%" /&gt;
        &lt;mx:TextArea id="textArea2"
                editable="false"
                width="100%"
                height="100%" /&gt;
    &lt;/mx:HDividedBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLEncoder_encodeValue_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLEncoder_encodeValue_test/bin/main.html" width="100%" height="350"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting objects to XML packets using the SimpleXMLEncoder class in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/',contentID: 'post-543',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'encodeValue()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/03/04/converting-objects-to-xml-packets-using-the-simplexmlencoder-class-in-flex/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Converting XML to objects using the Flex SimpleXMLDecoder class</title>
		<link>http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/</link>
		<comments>http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 03:04:12 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[SimpleXMLDecoder]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLDocument]]></category>
		<category><![CDATA[decodeXML()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/</guid>
		<description><![CDATA[<p>Similar to the previous post, &#8220;<a href="http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/">Converting XML to objects using the Flex HTTPService MXML tag</a>&#8220;, the following example shows how you can use the decodeXML() method in the SimpleXMLDecoder class to convert an XMLDocument object into an ActionScript Object object.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLDecoder_decodeXML_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- [...]]]></description>
			<content:encoded><![CDATA[<p>Similar to the previous post, &#8220;<a href="http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/">Converting XML to objects using the Flex HTTPService MXML tag</a>&#8220;, the following example shows how you can use the <code>decodeXML()</code> method in the SimpleXMLDecoder class to convert an XMLDocument object into an ActionScript Object object.</p>
<p>Full code after the jump.</p>
<p><span id="more-194"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLDecoder_decodeXML_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="serv.send();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.xml.SimpleXMLDecoder;

            private function serv_result(evt:ResultEvent):void {
                /* Convert XMLNode to XMLDocument. */
                var xmlStr:String = evt.result.toString();
                var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
                var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                var resultObj:Object = decoder.decodeXML(xmlDoc);
                /* Assign the values... */
                nameText.text = resultObj.album.name;
                img0Text.text = resultObj.album.images.image[0];
                img1Text.text = resultObj.album.images.image[1];
                img2Text.text = resultObj.album.images.image[2];
            }

            private function serv_fault(evt:FaultEvent):void {
                // Show the error label.
                error.text += evt.fault.faultString;
                error.visible = true;
                // Hide the form.
                form.visible = false;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:String id="XML_URL"&gt;album.xml&lt;/mx:String&gt;

    &lt;mx:HTTPService id="serv"
            url="{XML_URL}"
            resultFormat="xml"
            result="serv_result(event);"
            fault="serv_fault(event);" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="{XML_URL}" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Label id="error"
            color="red"
            fontSize="36"
            fontWeight="bold"
            visible="false"
            includeInLayout="{error.visible}"/&gt;

    &lt;mx:Form id="form"
            includeInLayout="{form.visible}"&gt;
        &lt;mx:FormItem label="resultObj.album.name:"&gt;
            &lt;mx:Label id="nameText" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[0]:"&gt;
            &lt;mx:Label id="img0Text" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[1]:"&gt;
            &lt;mx:Label id="img1Text" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[2]:"&gt;
            &lt;mx:Label id="img2Text" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLDecoder_decodeXML_test/bin/album.xml">View album.xml</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;album&gt;
    &lt;name&gt;One&lt;/name&gt;
    &lt;images&gt;
        &lt;image&gt;image1.jpg&lt;/image&gt;
        &lt;image&gt;image2.jpg&lt;/image&gt;
        &lt;image&gt;image3.jpg&lt;/image&gt;
    &lt;/images&gt;
&lt;/album&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLDecoder_decodeXML_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/SimpleXMLDecoder_decodeXML_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting XML to objects using the Flex SimpleXMLDecoder class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/',contentID: 'post-194',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'decodeXML()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-simplexmldecoder-class/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

