Skip to main content
Participant
July 31, 2009
Question

xml descendant traversal

  • July 31, 2009
  • 2 replies
  • 627 views

Hi,

When calling the following piece of code, I get two different results from the same descendant path for some reason:

var xmlt:XML =
<xml xmlns="http://blabla">
<animal type="sheep" >
  <name>josh</name>
  <age>2</age>
</animal>
<animal type="cow" >
  <name>jim</name>
  <age>2</age>
</animal>
</xml>

var ns:Namespace = new Namespace("http://blabla");
default xml namespace = ns;
trace("first attempt:" + xmlt..name[0]); // results in josh
trace("second attempt" +  xmlt..name[0] ); // results in undefined?

Any reason why the two are not the same? I got to this when trying to figure out why some code worked and other parts didn't... beats the hell out of me. (btw: I use a Logger instead of the trace, but don't think it matters here)

Regards

This topic has been closed for replies.

2 replies

July 31, 2009

Very interesting. I get the inverse: undefined on the first trace and "josh" on the second.

And to add to the weirdness, this works

var ns:Namespace = new Namespace("http://blabla");
default xml namespace = ns;


trace(xmlt..*.(localName()=="name")[0])// results in josh

trace("first attempt:" + xmlt..name[0]); // results in josh
trace("second attempt" +  xmlt..name[0] ); // results in josh

AlasiacAuthor
Participant
August 3, 2009

Thanks for trying this out, it does add a bit to the weirdness. Sounds like this may actually be some kind of bug?

kglad
Community Expert
Community Expert
July 31, 2009

show all your xml related actionscript.

AlasiacAuthor
Participant
August 3, 2009

The piece of code I provided is the one I used to test it. Only difference is that I tried it with Logger.info instead of trace (it logs messages to the firebug console).