Flex,XML后代

时间:2011-03-17 07:26:25

标签: xml flex actionscript-3

我想获得所有xml元素(xml后代),它们具有以下属性:

<books>
    <book concept="rr" author="xx"/>
    <book concept="tt" />
    <book concept="yy" />
    <book concept="uu" author="xx"/>
</books>

我需要对包含author属性的xml节点执行xml后代搜索 结果应该是:

<book concept="rr" author="xx"/>
<book concept="uu" author="xx"/>

2 个答案:

答案 0 :(得分:1)

这应该回答你的问题:

var booksXML: XML = <books>
    <book concept="rr" author="xx"/>
    <book concept="tt" />
    <book concept="yy" />
    <book concept="uu" author="xx"/>
</books>

for each (var xmlBook: XML in booksXML.children())
{
    if (xmlBook.@author != undefined)
        trace(xmlBook.toXMLString());
}

答案 1 :(得分:0)

或使用XML选择器:

var booksXML: XML = <books>
    <book concept="rr" author="xx"/>
    <book concept="tt" />
    <book concept="yy" />
    <book concept="uu" author="xx"/>
</books>

var haveAuthor:XMLList = booksXML.book.(attribute("author").length() > 0);
//booksXML.book.(@author) won't work