2

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

AnandMeena
  • 528
  • 3
  • 11
  • 26

3 Answers3

4

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());
}
Marcela
  • 3,728
  • 1
  • 15
  • 21
  • Thanks Marcela :-), Now categoryList has values. But how can I get inner values of entry node. Again thanks for your efforts :-) – AnandMeena Jul 08 '14 at 13:31
  • I've updated my example to include grabbing the author's name, however I was unable to find in the provided XML any element named `item`, so I'm not sure what you're trying to access in your above code sample. – Marcela Jul 08 '14 at 15:52
2

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;
BotMaster
  • 2,233
  • 1
  • 13
  • 16
1

Change declaration of categoryList to:

var categoryList:XMLList = x.entry;

It should loop through entry nodes now.

Petr Hrehorovsky
  • 1,153
  • 2
  • 14
  • 16