ActionScript - 仅使用后代访问器和属性遍历 XML?
var myXML:XML = <root>
<first>
<a title = "First Letter">
01234
</a>
<b title = "Second Letter">
56789
</b>
</first>
</root>
我想遍历上面的 XML 仅搜索一个属性。我不知道
或其子级( 和
),甚至不知道哪个级别包含属性的元素(XML 可能比我的示例更深)。
似乎后代访问器无法根据元素的属性查找元素。例如,我想遍历 XML 并找到具有属性“第二个字母”的元素。
trace(myXML..(@title == "Second Letter"));
难道不能从根开始遍历XML并通过属性定位元素吗?
var myXML:XML = <root>
<first>
<a title = "First Letter">
01234
</a>
<b title = "Second Letter">
56789
</b>
</first>
</root>
i would like to traverse the above XML searching only for an attribute. i don't know about <first>
or its children (<a>
and <b>
), or even which level the element containing the attribute (the XML can be much deeper than my example).
it seems that the descendent accessor does not work with finding elements based on their attribute. for example, i want to traverse the XML and find the element with the attribute "Second Letter".
trace(myXML..(@title == "Second Letter"));
is it not possible to traverse an XML from the root and locate an element by an attribute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搜索具有 属性< 的任何节点/a>
title
,这里不能使用 e4x @title 表示法,因为并非所有节点都有属性 title,因此您将收到编译时错误:Search for any node that have an attribute
title
, here you can't use e4x @title notation because not all node have an attribute title so you will get a compile time error :