Over the past few days I've been encountering problems reading XML nodes where there is a default namespace defined in the xml.
For example:
var example1:XML = <RootNode>
<Child>This is the child</Child>
</RootNode> ;
trace(example1.Child); // traces 'This is the child'
var example2:XML = <RootNode xmlns="http://tempuri.org/">
<Child>This is the child</Child>
</RootNode> ;
trace(example2.Child); // traces nothing
The simple solution would be to not include the namespace definition in the xml, but when the xml is server generated that isn't really an option.
Roger Braunstein writes that the problem is that example2.Child returns null because it is searching for a non-namespaced node where all the nodes exist in the xmlns namespace (I'll take his word on that) and that a solution is to define the namespace in an .as file and then set your xml reading code to use the namespace eg:
//xmlns.as
package
{
public namespace xmlns = "http://tempuri.org/";
}
//in your xml reading class
use namespace xmlns;
var example3:XML = <RootNode xmlns="http://tempuri.org/">
<Child>This is the child</Child>
</RootNode> ;
trace(example3.Child); // traces 'This is the child'