2011-03-17 55 views
1

我想所有的XML元素(XML的後代),它有這樣一些屬性:的Flex,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"/> 

回答

0

Ø r使用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 
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 ([email protected] != undefined) 
     trace(xmlBook.toXMLString()); 
}