【问题标题】:Flex / Actionscript - why wont 'XML.ignoreWhitespace = false' work?Flex / Actionscript - 为什么“XML.ignoreWhitespace = false”不起作用?
【发布时间】:2011-04-19 01:22:10
【问题描述】:

以下简单代码显示了我如何尝试在我的 XML 中保留空白,但它不起作用!知道我在这里做错了什么吗? (注意 '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>

请帮忙...谢谢!

【问题讨论】:

    标签: xml apache-flex actionscript-3 flex4


    【解决方案1】:

    使用 CDATA 格式化文本节点并保留空格:

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

    Ben 关于ignoreWhitespace 的意思是对的。

    【讨论】:

      【解决方案2】:

      我很确定 ignoreWhitespace 可以忽略 xml 标记之间的格式化空格和制表符,但它不会修剪文本节点内的文本。

      this brief intro

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-18
        • 1970-01-01
        • 2020-07-06
        • 1970-01-01
        • 2017-05-17
        • 1970-01-01
        • 2019-04-05
        • 1970-01-01
        相关资源
        最近更新 更多