Given the following sample XML (here I am showing hard-coded, but normally I load from an external file):
var myXML:XML = new XML('
<xmlout xmlns:ns1="http://some.namespace.com/ns1" xmlns:ns2="http://some.namespace.com/ns2" xmlns:ns3="http://some.namespace.com/ns3">
<data>
<item>
<ns1:id>some_id</ns1:id>
</item>
</data>
</xmlout>');
I am storing the namespaces as namespace objects in an object, like:
var xmlNamespaces:Object = {};
for (var i:uint = 0; i < myXML.namespaceDeclarations().length; i++) {
var ns:Namespace = myXML.namespaceDeclarations()[i];
xmlNamespaces[ns.prefix] = new Namespace(ns.prefix, ns.uri);
}
I am trying to do something like:
trace(myXML.data.item.xmlNamespaces["ns1"]::id.value);
Any idea if this is possible? I have not had any success. Thanks!
Edit:
I should note that I can do this, with no problem, using:
default xml namespace = xmlNamespaces.ns1;
var id:String = myXML.data.item.id;
I am specifically trying to figure out how to eliminate having to set the default namespace every time…
Sorry this has been taking me so long to get back to you as I am sure you probably needed it yesterday.
I was on the road for 8 hours today.
Writing inline XML
requiresthe use of a singleroot nodeto define the body of the XML document.Your first issue is you wrapped everything with a single quote. Take it out the parameter is not a string.
Your other issue as stated above you need to wrap it with a root tag.
This code compiles fine in flash cs4 let me know if you still can’t get that to work.
Notice in the code below I never reference the root node.