atom feed xmlns attribute messes up AS3's XML-parsing?
Wanna see something interesting?
var xml:XML = XML(<feed><entry />开发者_C百科<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"><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.
Here are possible workarounds:
var xml:XML = XML(<feed xmlns="http://www.w3.org/2005/Atom"><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
精彩评论