views:

509

answers:

1

Wanna see something interesting?

var xml:XML = XML(<feed><entry /><entry /><entry /></feed>);
trace(xml.entry.length())   // returns 3

Makes sense, right? Now let's add this attribute...

var xml:XML = XML(<feed xmlns="http://www.w3.org/2005/Atom"&gt;&lt;entry /><entry /><entry /></feed>);
trace(xml.entry.length())   // returns 0

Well that can't be right. Let's try it with a different attribute.

var xml:XML = XML(<feed test="okay"><entry /><entry /><entry /></feed>);
trace(xml.entry.length())   // returns 3

Anyone know what would cause this? I used atom as an example, but any 'xmlns' attribute on the root node seems to have this effect. The value returned is straight up false - there are obviously still 3 'entry' child nodes regardless of the attributes their parents possess.

+4  A: 

Here are possible workarounds:

var xml:XML = XML(<feed xmlns="http://www.w3.org/2005/Atom"&gt;&lt;entry /><entry /><entry /></feed>) ;
trace(xml.entry.length()) ;
// output: 0

var ATOM:Namespace = new Namespace( "http://www.w3.org/2005/Atom" );
trace(xml.ATOM::entry.length()) ;
// output: 3

default xml namespace = ATOM;
trace(xml.entry.length()) ;
// output: 3

Update

LiveDocs.Adobe.Com

St.Woland
Nice, apparently we came to the same conclusion at the same time. I'll let you have the 'accepted answer,' though.
matt lohkamp
another thing you can do to shortcut it a bit is -var atom:Namespace = xml.namespace() // picks up the defaulttrace(xml.atom::entry.length()) ;... and the advantage of this is that it'll work even if there are no namespaces defined, which is pretty cool.
matt lohkamp