tags:

views:

826

answers:

2
+1  Q: 

Flex String to XML

I have a string in XML format and I want to use this string as flex XML type as following :

This is my string :

<Graph>
   <Node id="1" name="1" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
   <Node id="2" name="2" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
   <Node id="3" name="3" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
</Graph>

I cant pass this to an API, it complains that this is string and it expects an XML type. How can i convert this string to XML with minimum effort, ie: without iterating the string and the nodes etc. Is there such method as : var data:XML = new XML(str:String);

How can i solve this?

+3  A: 

This blog entry suggests that the following would work:

var sText:String = "<your-xml-here />";
var xData:XML    = XML(sText);
Tomalak
interesting, i thought of that, but didnt try it as you can see in the question. i ll try now.
That worked actually. Thanks.
You could also change the last line toxData = sText as XML;
robmcm
@robmcm: Sure, done.
Tomalak
+2  A: 

To add to Tomalak's comment, you could also simply define:

var xData:XML = <Graph>
                   <Node id="1" name="1" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
                   <Node id="2" name="2" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
                   <Node id="3" name="3" nodeColor="0x333333" nodeIcon="center" x="10" y="10" />
                </Graph>;
Michael Brewer-Davis
yeah that works. thank you.