代码之家  ›  专栏  ›  技术社区  ›  Bartvbl

如何访问AS3中的xmlList节点

  •  1
  • Bartvbl  · 技术社区  · 16 年前

    我现在正在处理一个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)的actionsicRpt代码:

    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。 当我尝试使用这个.DropLocationsXML[1]和valueof()方法时,同样的情况也是如此。
    如您所见,我只需要从每个特征标记中提取x和y属性。trace()语句提供上面显示的XML输出。
    是否有人知道如何访问XML列表的根节点,以便我可以使用x和y属性?

    1 回复  |  直到 16 年前
        1
  •  3
  •   maxmc    16 年前
    for each (var x : XML in dropLocationsXML.feature) {
        trace("xml: "+x.@type);
    
    }