简体   繁体   中英

atom feed xmlns attribute messes up AS3's XML-parsing?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM