AnandMeena
AnandMeena

Reputation: 578

loop through complex xml nodes actionscript

I am reading an xml file in actionscript.

I need to loop through each node named "entry" as showing in below image :-

Can anyone help me ?

enter image description here

I am trying below code. but it not working :-

var categoryList:XMLList = x.feed.@entry;

                for each(var category:XML in categoryList)
                {
                    trace(category.@name);

                    for each(var item:XML in category.item)
                    {
                        trace("  "+item.@name +": "+ item);
                    }
                }

"entry" node also has some inner nodes, I also want to read those nodes.

Thanks

Upvotes: 2

Views: 194

Answers (3)

BotMaster
BotMaster

Reputation: 2223

Better is:

var n:Namespace = new Namespace("http://www.w3.org/2005/Atom");
default xml namespace = n;
var categoryList:XMLList = x.entry;//no namespace type access
//etc
default xml namespace = null;

Upvotes: 2

Marcela
Marcela

Reputation: 3738

This XML is using the namespace http://www.w3.org/2005/Atom, so you have to account for that:

var n:Namespace = new Namespace("http://www.w3.org/2005/Atom");
var categoryList:XMLList = x.n::entry;

Update: In order to access child nodes, you will need to continue to use the namespace

for each(var category:XML in categoryList)
{
    // this traces the name of the author
    trace(category.n::author.n::name.toString());
}

Upvotes: 4

Petr Hrehorovsky
Petr Hrehorovsky

Reputation: 1153

Change declaration of categoryList to:

var categoryList:XMLList = x.entry;

It should loop through entry nodes now.

Upvotes: 1

Related Questions