【问题标题】:How to access XMLList nodes in AS3如何在 AS3 中访问 XMLList 节点
【发布时间】:2011-03-11 21:31:02
【问题描述】:

我目前正在处理一个 XML 列表,如下所示:

<feature type="startLocation" value="1" x="15" y="3"/>
<feature type="startLocation" value="1" x="15" y="4"/>
<feature type="startLocation" value="1" x="15" y="5"/>
<feature type="startLocation" value="1" x="15" y="6"/>
<feature type="startLocation" value="1" x="15" y="7"/>

这是解析此 XMLList(名为 this.dropLocationsXML)的 ActionScirpt 代码:

public function dropUnit()
{
    var numX:int;
    var numY:int;
    var feature:XMLList;
    trace(this.dropLocationsXML);
    for(var i:int = 0; i < this.dropLocationsXML.length(); i++)
    {
        feature = this.dropLocationsXML.child(i);
        numX = -16 + (feature.@x)*35;
        numY = 4 + (feature.@y)*35;
    }
}

现在,当我尝试使用 child() 函数访问这个 XMLList 时,我得到了一个空的 XMLList。 当我尝试使用 this.dropLocationsXML[1] 和 valueOf() 方法时也是如此。
如您所见,我只需要从每个特征标签中提取 x 和 y 属性。 trace() 语句给出了上面显示的 XML 输出。
有谁知道如何访问 XML 列表的根节点,以便我可以使用 x 和 y 属性?

【问题讨论】:

    标签: xml actionscript-3


    【解决方案1】:
    for each (var x : XML in dropLocationsXML.feature) {
        trace("xml: "+x.@type);
    
    }
    

    【讨论】:

    • 啊,我明白了。我假设你的 xml 是这样的:
    • 这几乎成功了:for each (var x : XML in dropLocationsXML) { trace("xml: "+x.@x); }
    猜你喜欢
    • 1970-01-01
    • 2013-09-05
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    相关资源
    最近更新 更多