原子饲料xmlns属性弄乱了的AS3的XML解析?原子、饲料、属性、xmlns

2023-09-09 21:46:28 作者:羁绊i

想看看一些有趣的事情?

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

任何人都知道什么原因呢?我用原子作为一个例子,但在根节点上的任何'的xmlns'属性似乎有这样的效果。返回的值是直线上升虚假的 - 有显然还是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

更新

LiveDocs.Adobe.Com