Hi!
XML is cool in flex, but I have an annoying problem to solve, caused by what I can imagine is a feature. You see, when you have just one tag of something, it creates an object which is not an array. But when finds more than one, it puts it on an array structure.
I want to solve it elegantly. Any recommendation.
Example: this illustrates it, being the result of a HTTP request:
private function initXMLRes(event:ResultEvent):void
{
var resObj:Object = event.result;
//
for each(var i:Object in resObj.specifictag)
{
// to use specifictag attributes, etc. example:
Alert.show(specifictag.name);
}
}
The code before will work with 2+ items. It will accept this xml:
<specifictag name="one" /><specifictag name="two" />
... but not this one:
<specifictag name="one" />
I could check the format of resObj.specifictag (to check if it is has an array) and then duplicate the code (for each case). But -even if it's calling a function- I don't think it is an elegant solution.
Well, I hope someone has a good idea on this matter. (I know from experience that SO has much more C++ experts than flex, but well...)
The perfect thing would be that HTTPrequest handled every tag in a consistent way (using always arrays... though I'm guessing that that would also have its drawbacks).
Thanks!