2011-04-19 43 views
0

以下簡單代碼顯示了我如何在XML中保留空白區域,但它不起作用!任何想法我在這裏做錯了嗎? (注意之前的空間「的世界!」Flex/Actionscript - 爲什麼不能'XML.ignoreWhitespace = false'工作?

<?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

使用CDATA與保護空格格式化文本節點:

<sentence><word1>hello</word1><word2><![CDATA[ world!]]></word2></sentence> 

本是正確的關於ignoreWhitespace的含義。

+0

解釋...謝謝! – 2011-04-19 19:22:45

0

我敢肯定ignoreWhitespace工作忽略格式化XML標籤之間的空格和製表符,但它不文本節點內修剪文字

this brief intro