如何通过Flex / actionscript中的属性名/值来查找特定的xml数据
发布时间:2020-12-15 02:17:16 所属栏目:百科 来源:网络整理
导读:从一些xml我想要找到具有特定属性和值的项目. 这里是xml的例子: node node node special NAME="thisone"/special /node node specialdont want this one/special /node /node/node (节点可以包含节点…) 我需要找到第一个基于它的属性名为“NAME”和值“thi
从一些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(); 如果你知道你想要的节点是一个特殊的,那么你可以使用: var selected:XMLList = xml..special.(attribute("NAME") == "thisone"); 代替.这是一个nice E4X tutorial. 如果您使用@NAME ==“thisone”语法,那么您需要在所有XML节点上使用NAME属性,但不要使用attribute()运算符语法. 我在上面添加了parent()调用;您只能在条件中使用子代直接获取父项: xml..node.(child("special").attribute("NAME") == "thisone"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |