views:

36

answers:

1

This is making me feel stupid :-). Say I start at a leaf node, and I traverse up the tree by using .parent(). I need an exit condition once it hits root. At the moment, I'm using parent.@name != "root", where name is just an attribute, but shouldn't I be able to check the type of element as well? How? Also, is there another way to end the traversal in as3?

+3  A: 

Assuming you are using the XMLNode object:

if (currentNode.parentNode == null)
    // Root

And if you are using the XML object:

if (!xmlNode.parent())
    // Root
clownbaby
Thanks! also, how do you check what the type of an xml element is?
Gary
If you are asking how to check if you are using XMLNode VS XML... then the answer is: you should already know because you are writing the code.If you are asking if the XMLNode you are working on is text or an element, look at XMLNode.nodeType.Hope this helps.
clownbaby