【问题标题】:HOw to find specific child node in XML using AS3 flash如何使用 AS3 flash 在 XML 中查找特定的子节点
【发布时间】:2010-06-02 03:29:11
【问题描述】:

我有这个 xml

var testXML:XML =    <family>
    <father name1="tom" age="5" ><father1 name1="test1"/><father2 name1="test2"/></father>
    <mother name1="tomylee" age="55" ><mother1/><mother2/></mother>
    <sister name1="sister1" age="35" ><sister1/><sister2/></sister>
    </family>;

我想获取 name1 = test1 的子节点,但我只知道家庭

有没有类似的东西

trace (testXML.children(@name1="test1");  

我只知道家庭节点,我不知道那个节点在父亲内部的位置

是否可以在根节点上应用任何过滤器来查找内容

【问题讨论】:

    标签: xml actionscript-3


    【解决方案1】:

    使用 hasOwnProperty 和一些逻辑运算符

    trace( testXML..*.( hasOwnProperty("@name1") && @name1 == "tom" ));
    trace( testXML..*.( hasOwnProperty("@name1") && @name1 == "test1" ));
    

    我修改了你的 XML 以至少显示一个结果

    var testXML:XML =    <family>
                <father name1="tom" age="5" ><father1 name1="test1">father1</father1><father2 name1="test2"/></father>
                <mother name1="tomylee" age="55" ><mother1/><mother2/></mother>
                <sister name1="sister1" age="35" ><sister1/><sister2/></sister>
                </family>;
    

    寻找证据

    <father name1="tom" age="5">
    <father1 name1="test1">father1</father1>
    <father2 name1="test2"/>
    </father>
    

    更新: -----这里是 --> .*

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-06
      • 1970-01-01
      相关资源
      最近更新 更多