user587159
user587159

Reputation: 357

Flex, XML Descendents

I want to get all xml elements (xml descendents) which have some attributes like:

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

I need to perform a xml descendent search for xml nodes with author attribute containing results should be:

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

Upvotes: 1

Views: 344

Answers (2)

alxx
alxx

Reputation: 9897

Or with XML selectors:

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

Upvotes: 0

splash
splash

Reputation: 13327

This should answer your question:

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());
}

Upvotes: 1

Related Questions