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

3 Answers 3

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());
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Marcela :-), Now categoryList has values. But how can I get inner values of entry node. Again thanks for your efforts :-)
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.
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;

Comments

1

Change declaration of categoryList to:

var categoryList:XMLList = x.entry;

It should loop through entry nodes now.

2 Comments

No, its not entering inside loop, categoryList is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.