This is the best method I found so far to check is an xml attribute exists and have some value set.
You can use the following function to do it:
public function isSetXMLAttribute(__xml:XML, __attr:String):Boolean
{
if(!__xml) return false;
if(("@"+__attr) in __xml)
{
if(__xml.@[__attr].toString() == "") return false;
return true;
}
return false;
}
Assuming you have the following xml object:
var xml:XML =
<item name="somename" />
Use the function like that to check the @name attribute:
var item:XML = xml[0]; var exists:Boolean = isSetXMLAttribute(item, "name");
That’s it.