So I am pulling in this XML data using AS3 and storing it as myXML:
<Questions>
<id>1</id>
<question>
This is question 1.
</question>
</Questions>
<Questions>
<id>3</id>
<question>
This is question 3.
</question>
</Questions>
Now I want to check if an id is found within that XML. I am currently using this, but it always traces "NOT FOUND" -
for (var i: Number = 1; i < 3; i++) {
if (myXML.Questions.(@id == i).length() > 0) {
trace("FOUND")
} else {
trace("NOT FOUND");
}
}
There are no loop necessary. Vesper solution would work but in theory is very expensive and slow. PO was also pretty close but he's using @id as if the id element was an attribute. The solution is simply:
You either got a valid XMLList or you don't but that's all it takes.
Also do not use that code logic:
It creates an unnecessary additional xml search since if true you would then have to call "xml.Questions.(id == 1)" again to get the list. Instead call it and store the result first, then check the length if you wish so.