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=""&gt;

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:


with namespaces:


In the above example, xmlns would be a Namespace object that references the default XML namespace.

Check out the tasty sample code here.