首页 > 解决方案 > 是否有另一种方法可以在没有 E4X 语法的情况下过滤 xml 元素?

问题描述

我正在尝试使用Jangaroo将一些旧的动作脚本代码(Flash 应用程序的一部分)编译为 JS 。Jangaroo 不支持 E4X 语法,并且在双点运算符..或括号过滤器等方面失败a.(CONDITION)。所以我需要使用普通的 ActionScript 重写这些代码部分。

对于双点运算符,我使用了方法descendants(),但我找不到编写括号过滤器的替代方法。

这是我的原始代码:

B = xml..destination.(@id == someId)

我现在写了:

B = xml.descendants("destination").(@id == someId)

但我仍然想删除.(@id == someId).

我正在考虑类似的事情:

if (xml.descendants("destination").attribute("id") == someId)
{
B = xml.descendants("destination")
}

这可能吗?

标签: actionscript-3actionscripte4x

解决方案


所以这就是我如何进行的。我没有测试过它的功能,但是编译器通过了它。

var destinations:XMLList = null;
for each (var elm in xml.descendants("destination") )
{
 if ( elm.attribute("id") == someId )
 {
    destinations += elm;
 }
}

推荐阅读