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

有没有可能在XMLAS3flash中获取特定节点的子节点

  •  0
  • Joh  · 技术社区  · 15 年前

    我有很多子xml文件,然后还有更多的子xml文件。

    喜欢

    <level1>
    <child id=1 > <nodes....> </child1>
    <child id=2 > <nodes....> </child1>
    <child id=3 > <nodes....> </child1>
    <child id=4 > <nodes....> </child1>
    </level1>
    

    是否可以在AS3中获取id=1的child的子节点

    2 回复  |  直到 15 年前
        1
  •  0
  •   Patrick    15 年前

    是的,可以用 filter xml上的函数:

    var xml:XML=<level1>
    <child id="1" > <nodes>1</nodes> </child>
    <child id="2" > <nodes>2</nodes> </child>
    <child id="3" > <nodes>3</nodes> </child>
    <child id="4" > <nodes>4</nodes> </child>
    </level1>;
    
    // list of children with id=1
    var xl:XMLList=xml.child.(@id=="1"); //<== here filter xml based on attribute "id"
    for each (var node:XML in xl){
      trace(node.toString());
    }
    
        2
  •  0
  •   Ben Hughes    15 年前

    我现在没有时间给出详细的答案,但是请阅读e4x,它可以让你做你需要的事情。稍后我将尝试发布一个示例。