【问题标题】:change the characters of xml in actionscript在actionscript中更改xml的字符
【发布时间】:2009-06-15 09:54:32
【问题描述】:

嗨社区我有以下问题,

给定这个 xml

<test>
    <comp>
        <id>1</id>
        <content>bar</content>
    </comp>
    <comp>
        <id>2</id>
        <content>foo</content>
    </comp>
</test>

我想更改 id 为 2 的 comp 元素内容的值。因此我使用 foreach 循环进行循环

for each (var x : XML in testXML.children()) {
                    if (x.id == 2) {
                        for each (var element : XML in x.Children()) {
                            if (element.localName() == "content") {
                                element = "new content";
                            }
                        }
                    }
                }

现在当到达element = "new content"; 点时,我的程序告诉我我不能给元素新内容的值,因为这是一个字符串,而元素是 xml。我怎样才能做到这一点?

提前致谢

塞巴斯蒂安

【问题讨论】:

  • 好的,刚刚发现...我使用了 element.* = "new content" 现在它可以工作了

标签: xml apache-flex actionscript-3


【解决方案1】:

尝试使用 E4X 而不是循环。

要访问元素,请使用:

xml.comp.(id == 2).content

要修改其内容,请使用

xml.comp.(id == 2).content.* = "new content";

短得多:)

【讨论】:

  • 非常感谢您的回答,我喜欢 E4X 但不知道条件。这很棒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 2012-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多