原子饲料xmlns属性弄乱了的AS3的XML解析? [英] atom feed xmlns attribute messes up AS3's XML-parsing?

查看:231
本文介绍了原子饲料xmlns属性弄乱了的AS3的XML解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想看看一些有趣的事情?

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

更新

<一个href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000130.html">LiveDocs.Adobe.Com

这篇关于原子饲料xmlns属性弄乱了的AS3的XML解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆