【问题标题】:XML object removes namespace FlexXML 对象移除命名空间 Flex
【发布时间】:2011-06-30 14:19:06
【问题描述】:

使用以下代码,一切都按预期工作,并且我在跟踪打印输出中保留了默认命名空间和 xsi 命名空间。

var tempData = <objects xmlns="http://www.spicefactory.org/parsley" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                    </objects>


    var scriptParent:XML = <xml></xml>;
    scriptParent.appendChild(tempData);
    trace ("scriptParent " + scriptParent);

但是,如果我在我的 mxml 文件中使用以下代码从外部加载我的 xml:

<fx:Declarations>
    <fx:XML  xmlns=""  id="script" source="script.xml"/>
</fx:Declarations>

然后这个打印的结果最终会删除 xsi 命名空间。我能做些什么来保留它?谢谢。

var scriptParent:XML = <xml></xml>;
scriptParent.appendChild(script);
trace ("scriptParent " + scriptParent);

【问题讨论】:

    标签: xml apache-flex namespaces


    【解决方案1】:

    我过去曾遇到过这个问题,虽然恐怕我无法回答为什么会发生这种情况,但似乎 Flex 从导入的 XML 中剥离了任何“未使用”的命名空间(即没有子节点直接引用命名空间)。以下与您的问题类似的示例说明了这一点:

    文本.xml:

    <?xml version="1.0"?>
    <objects xmlns="http://www.spicefactory.org/parsley" xmlns:myTestNs="http://test.com" xmlns:myUnusedNs="http://testUnused.com">
        <myTestNs:test>Test text node</myTestNs:test>
    </objects>
    

    使用与上面列出的相同的方法,输出如下:

    <xml>
      <objects xmlns="http://www.spicefactory.org/parsley">
        <myTestNs:test xmlns:myTestNs="http://test.com">Test text node</myTestNs:test>
      </objects>
    </xml>
    

    如果有人能解释为什么会发生这种情况,我会很感兴趣,因为在许多用例中,我们希望维护所有命名空间声明,即使它们当前未使用。

    【讨论】:

      猜你喜欢
      • 2019-02-09
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多