With AS3's XML find/filter operators, how to find children of an XML node when a tag is repeated?



This is probably best illustrated by an example:



var xml1:XML = new XML("<root> <key>value1</key> </root>");
var xml2:XML = new XML("<root> <key>value1</key> <key>value2</key> </root>");
var xml3:XML = new XML("<root> <key>value1</key> <key2>value2</key2> </root>");
for each (var xml:XML in [ xml1, xml2, xml3 ])
{
var result:XMLList = xml.(key == "value1").key;
}


In all three cases, I expect the filtered XMLList to have one node (result.length() == 1). This is the case when operating on xml1 and xml3. However, nothing is found when filtering xml2 (result.length() == 0). The crucial difference seems to be that in xml2, the "key" child tag is repeated.


Is this a bug (compiler? runtime?) or am I doing something wrong?


No comments:

Post a Comment