简体   繁体   English

Flex / Actionscript-为什么'XML.ignoreWhitespace = false'不起作用?

[英]Flex / Actionscript - why wont 'XML.ignoreWhitespace = false' work?

The following simple codes show how I'm trying to keep white space in my XML but it doesn't work! 以下简单的代码显示了我如何尝试在XML中保留空白,但是它不起作用! Any idea what I'm doing wrong here? 知道我在做什么错吗? (note the space before 'world!' (请注意“世界!”之前的空格!

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

Please help... Thanks! 请帮忙...谢谢!

I'm pretty sure ignoreWhitespace works to ignore formatting spaces and tabs between the xml tags, but it doesn't trim text within a text node. 我敢肯定,ignoreWhitespace可以忽略xml标记之间的格式空间和制表符,但是它不会修剪文本节点内的文本。

See this brief intro 看到这个简短的介绍

Use CDATA to format your text nodes with preserving whitespaces: 使用CDATA来格式化带有保留空格的文本节点:

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

Ben is right about meaning of ignoreWhitespace . Ben对ignoreWhitespace含义是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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