E4X: Watch Your Namespace…

When using the new XML object in ActionScript 3 and parsing the data with E4X, if your XML data has a “xmlns” attribute- you may have a difficult time getting any accessible data out of it. The infuriating thing is that the process will fail silently without throwing any errors, returning null, undefined, or anything else…

The way around this is to explicitly let Flash know what namespace you are intending to use:

namespace xspf = "http://xspf.org/ns/0/";
use namespace xspf;

In this case, I am importing XSPF playlist data for an audio project.

5 thoughts on “E4X: Watch Your Namespace…”

  1. I wonder….

    can the namespace be interrogated dynamically instead? It’s not often that the namespace would change (and if it does it usually heralds other changes that would break your app anyway…)

    … just curious

    thanx

  2. While I can trace out the xmlns using xml.namespace(), it seems to be problematic when trying to apply that result as a default namespace.

    I’ve tried a lot of different things so far and nothing seems to be able to handle this exactly as I’d like.

Leave a Comment

Your email address will not be published. Required fields are marked *