AS3+XML/XMLList question

Given the following XML fragment:


Is there a better way to get the value of the Age than this?

var xl:XML = /* that fragment above */;
var age:int;
for (var i:int = 0; i < xl.length() - 1; i++) {
      ((xl[i].name() as QName).localName == 'key') &&
      (xl[i].text()[0] == 'age') &&
      ((xl[i+1].name() as QName).localName == 'int')
    ) {
       age = xl[i+1].text()[0];

That just seems like a horrible hack to me. No, I didn't create that XML file, I'm just working with what I was given. And no, you can't depend on the Age being after the Name, only that the tag after each Key will contain the value.

Published by

Rick Osborne

I am a web geek who has been doing this sort of thing entirely too long. I rant, I muse, I whine. That is, I am not at all atypical for my breed.