views:

31

answers:

1

I am building an application using Action script 3 I am retrieving some XML from the web however the node names are mms:Image mms:Results etc my action script compiler is throwing an error becuase it is not expecting to see the semi colon in the node name. How to I access the nodes?

thanks

+2  A: 

Those are XML namespaces and they can be a pain to use. Have a look at the Adobe documentation on Using XML namespaces.

Basically you have to get the namespace:

var mmsNS:Namespace = message.namespace("mms");

// alternatively for nested namespaces:

var mmsNS:Namespace = new Namespace("mms", " ... url of namespace ... ");

And then use it when you want to get the nodes that it is applied to:

var data:XML = message.@mmsNS::Results;

A shortcut if all of your xml is in a particular namespace is to set the default namespace:

default xml namespace = mmsNs;

edit: The XML namespace you are trying to access must be declared within the XML fragment:

<root xmlns:mms="http://example.com/mms"&gt;
    <mms:someNode someAttr="someVal" />
</root>

Have a look at the w3c docs for XML Namespaces to ensure your document is well-formed (maybe even pass it through a validator).

James Fassett
Thanks for that, I tried it out and i keep getting an error of "illegal value for namespace" any ideas?
Dreamguts
Also how do i find out what the url of the namespace is?
Dreamguts
The xml namespace must be declared within the XML. I'll add an example.
James Fassett
Amazing! thank you so much, that is working now!
Dreamguts