简体   繁体   中英

Serialize XML file in AS3

How can I serialize XML(meaning convert < to &lt; and > to &gt; etc...) using AS3. is there any build-in functionality or I have to use some regular expression to make global changes?

Any Suggestions?

the most simple way is using flash.xml::XMLNode as follows:

    var xml:XML = <xml/>;
    xml.appendChild(new XMLNode(XMLNodeType.TEXT_NODE,"te<s>t"));
    trace(xml.toXMLString());//<xml>te&lt;s&gt;t</xml>

according to adobe XMLNode is only for legacy support, but I find it much more robust and simple than XML , although it doesn't support E4X.

The E4X approach is:

    var value:String = "te<s>t";
    var xml:XML = <xml>{value}</xml>;
    trace(xml.toXMLString());//<xml>te&lt;s&gt;t</xml>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM