Atom feed XML attribute ruined AS3 XML parsing?

Want to see something interesting?

var xml:XML = XML(<feed><entry /><entry /><entry /></feed>);
trace(xml.entry.length())   // returns 3

It makes sense, right? Now 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

It’s good that it’s not so. Try using it with a different attribute.

var xml:XML = XML(<feed test="okay"><entry /><entry /><entry /></feed>);
trace(xml.entry.length())   // returns 3

Does anyone know what might cause this? I used the atom as an example, but any attribute "xmlns" in the root of the node seems to have this effect. The return value is directly false - obviously, there are still 3 'input child nodes, regardless of the attributes their parents possess.

+3
source share
1 answer

Here are some 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

+10
source

Source: https://habr.com/ru/post/1729459/


All Articles