开发者

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 s开发者_高级运维uch method as : var data:XML = new XML(str:String);

How can i solve this?


This blog entry suggests that the following would work:

var sText:String = "<your-xml-here />";
var xData:XML    = XML(sText);


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>;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜