Parsing multiple namespaces in AS3 January 29, 2009
Posted by headwinds in ASP.NET, Actionscript.add a comment

I was working with a .Net 3.5 developer today and it appears that soap the standard response has changed from 2.0.
I had encountered soap before and knew how to use the Namespace identifier in AS3 to target that nodes with the soap namespace. But this time around the response had multiple namespaces.
At first, I was a bit confused at how to get the xml list from this response. I could get to the Body node as a xml list but I couldn’t seem to parse it any further through E4X until I realized that, along with the “soap” namespace, I also needed to use the “http://smurfs.mobi/” namespace so that my path to the enemy list is actually:
var enemyXMLList:XMLList = envelope.soapNamespace::Body.smurfsNamespace::[requestName + "Response"].smurfsNamespace::["SMURFS"].smurfsNamespace::["Enemies"].smurfsNamespace::["enemy"];
not
var enemyXMLList:XMLList = envelope.soapNamespace::Body.SMURFS.Enemies.enemy
And even if you can’t see the namespace attribute as part of the node, I also discovered that its still there and you need to use if you want to access the nodes of each enemy like so:
for each ( var enemy:XML in enemyXMLList )
{
var enemyObj:Object = new Object();
enemyObj:Object.firstName = enemy.smurfsNamespace::EnemyName.toString();
}
Sample namespace helper class which parses the xml and returns an array of objects.
I’m sorry, but I think The Smurfs would make a terrible live action movie.