【问题标题】:How do I get the number of XML child nodes in Haxe Script?如何获取 Haxe 脚本中 XML 子节点的数量?
【发布时间】:2015-02-15 11:48:43
【问题描述】:

如何获取 Haxe Script 中 XML 子节点的数量?

在 AS3 中,我会写 node.children().length()。

假设在 Haxe 中,我有:

var node = FastXML.parse("<node><hello>Hi</hello><world/></node>");

在这种情况下,节点有 2 个孩子。如何在 Haxe 中获得这个?

【问题讨论】:

    标签: xml haxe


    【解决方案1】:

    由于Xml 本身是其子节点的可迭代对象,我们可以使用Lambda.count

    using Lambda; //Static Extension http://haxe.org/manual/lf-static-extension.html
    
    class Test {
        static function main() {
            var xml = Xml.parse("<node><hello>Hi</hello><world/></node>");
            var node = xml.firstChild(); //<node>
            trace(node.count()); //2
    
            var fast = new haxe.xml.Fast(Xml.parse("<node><hello>Hi</hello><world/></node>"));
            var node = fast.node.node; //<node>
            trace(node.x.count()); //2
        }
    }
    

    【讨论】:

    • 我无法正常工作。可能是因为我使用的是 as3hx 附带的 FastXML 类。但我找到了另一种方式:node.descendants().length();
    【解决方案2】:

    我找到了解决办法:

    node.descendants().length();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多