以下简单代码显示了我如何在XML中保留空格,但它不起作用!知道我在这里做错了吗? (注意'世界之前的空间!'
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.Alert;
XML.ignoreWhitespace = false;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
var xmlString:String =
"<sentence><word1>hello</word1><word2> world!</word2></sentence>";
trace(xmlString);
XML.ignoreWhitespace = false;
var xml:XML =
new XML(xmlString);
trace(xml.toXMLString());
Alert.show(xml.toXMLString());
}
]]>
</fx:Script>
</s:Application>
请帮忙......谢谢!
答案 0 :(得分:0)
我很确定ignoreWhitespace可以忽略xml标记之间的格式空格和制表符,但它不会修剪文本节点中的文本。
答案 1 :(得分:0)
使用CDATA格式化文本节点并保留空格:
<sentence><word1>hello</word1><word2><![CDATA[ world!]]></word2></sentence>
Ben对ignoreWhitespace
的意思是对的。