gpt4 book ai didi

xml - 如何在 flex/actionscript 中通过属性名称/值查找特定的 xml 数据

转载 作者:数据小太阳 更新时间:2023-10-29 01:42:10 25 4
gpt4 key购买 nike

我想从一些 xml 中找到具有特定属性和值的项目。

这是示例 xml:

<node>
<node>
<node>
<special NAME="thisone"></special>
</node>
<node>
<special>dont want this one</special>
</node>
</node>
</node>

(节点可以包含节点...)

我需要找到第一个,基于它有一个名为“NAME”的属性和“thisone”的值。

然后我需要它的父节点(节点)。

我试过这个:

specialItems = tempXML.*.(hasOwnProperty("NAME"));

但似乎什么也没做。

??

谢谢!

最佳答案

在 ActionScript 中,您通常会使用 E4X 而不是 XPath。你想要的可以这样实现:

var xml:XML = <node>...</node>;
var selected:XMLList = xml.descendants().(attribute("NAME") == "thisone");
var first:XML = selected[0];
var parent:XML = first.parent();

如果你知道你想要的节点是一个special,那么你可以使用:

var selected:XMLList = xml..special.(attribute("NAME") == "thisone");

相反。这是一个 nice E4X tutorial .

如果您使用 @NAME == "thisone" 语法,那么您确实需要在所有 XML 节点上使用 NAME 属性,但如果您使用 attribute() 运算符语法。


我在上面添加了 parent() 调用;您可以通过仅在有条件的情况下使用 child 直接获得 parent :

xml..node.(child("special").attribute("NAME") == "thisone");        

关于xml - 如何在 flex/actionscript 中通过属性名称/值查找特定的 xml 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2225864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com