The Adobe® Flex® 3 Language Reference provides some great examples when it comes to accessing XML elements and attributes using e4x.
However what it doesn’t show you is how to access those same elements and attributes when the XML object contains one or more namespace declarations.
Consider the following XML sample:
var response : XML =
<response xmlns:sample="http://userflex.wordpress.com/">
<statusCode>200</statusCode>
</response>;
Because of the namespace declaration, you can’t simply access the statusCode element with response.statusCode, despite the fact that the statusCode element resides in the default namespace.
What you need to do is iterate over the set of XML namespaces until you locate the default namespace. Then you can access any of the XML elements or attributes in the default namespace in nearly the same manner as before.
without namespaces:
response.statusCode
with namespaces:
response..xmlns::statusCode
In the above example, xmlns would be a Namespace object that references the default XML namespace.
Check out the tasty sample code here:
http://userflex.wordpress.privatepaste.com/cduVt2tL2i
Update: Code snippets I’ve posted using Private Paste are randomly disappearing, so if the above link no longer exists, here’s a backup.

1 comment
Comments feed for this article
October 10, 2008 at 7:49 am
Recent Links Tagged With "e4x" - JabberTags
[...] public links >> e4x Accessing XML with Namespace Declarations Using E4X Saved by nFavorites on Thu 09-10-2008 Flex Processing XML response from HTTPService Saved by [...]