AS3:所有键 + 来自 XML 属性的值

发布于 2024-07-19 01:52:41 字数 569 浏览 2 评论 0原文

<top>
    <item link="http://www.google.be"><![CDATA[test]]></item>
    <item link="http://www.google.be"><![CDATA[test]]></item>
    <item bold="true" link="http://www.google.be"><![CDATA[test]]></item>
</top>

我需要获取所有属性(键和值)

for each ( var item : XML in data.item )
{
     trace(item.attributes().name());
}

给出此错误

 TypeError: Error #1086: The name method only works on lists containing one item.

在第三项上

<top>
    <item link="http://www.google.be"><![CDATA[test]]></item>
    <item link="http://www.google.be"><![CDATA[test]]></item>
    <item bold="true" link="http://www.google.be"><![CDATA[test]]></item>
</top>

I need to get all the attributes (both key and value)

for each ( var item : XML in data.item )
{
     trace(item.attributes().name());
}

gives this error

 TypeError: Error #1086: The name method only works on lists containing one item.

on the 3th item

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

它在第三个项目上爆炸的原因是它有两个属性。 您使用的快捷方式仅在只有一个属性时才获取名称。 您需要将代码更改为以下内容:

for each (var item : XML in data.items)
{
    for each (var attr : XML in item.attributes())
    {
        trace(attr.name());
    }
}

编辑:名称后的括号丢失。

The reason it's blowing up on the third item is that it has two attributes. You are using a shortcut that only gets the name if there is only one attribute. You need to change your code to the following:

for each (var item : XML in data.items)
{
    for each (var attr : XML in item.attributes())
    {
        trace(attr.name());
    }
}

Edit: Brackets after name were missing.

季末如歌 2024-07-26 01:52:41

使用 attr.valueOf() 获取该属性的值

for each (var item : XML in data.items)
{
    for each (var attr : XML in item.attributes())
    {
        trace(attr.name()+":"+ attr.valueOf());
    }
}

Use attr.valueOf() to get the value of that attribute

for each (var item : XML in data.items)
{
    for each (var attr : XML in item.attributes())
    {
        trace(attr.name()+":"+ attr.valueOf());
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文