atom feed xmlns attribute messes up AS3's XML-

2019-05-11 16:30发布

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"><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.

1条回答
Emotional °昔
2楼-- · 2019-05-11 16:47

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

查看更多
登录 后发表回答