Re: Cocoa-dev Digest, Vol 6, Issue 794
Re: Cocoa-dev Digest, Vol 6, Issue 794
- Subject: Re: Cocoa-dev Digest, Vol 6, Issue 794
- From: Graham Cox <email@hidden>
- Date: Thu, 28 May 2009 22:59:51 +1000
On 28/05/2009, at 10:45 PM, McLaughlin, Michael P. wrote:
I'm familiar with recursion; that is what prompted my query.
However, the
tree-traversal documentation at
http://devworld.apple.com/documentation/Cocoa/Conceptual/NSXML_Concepts/Arti
cles/TraversingTree.html#//apple_ref/doc/uid/TP40001257
seems to indicate that the built-in traversal method, nextNode, is
non-recursive (in the usual sense). This method will return non-nil
until
the whole tree is finished. I was looking for some indicator that I
had
finished just a subtree. [Perhaps level will work.]
(Just forwarding this to the list, in case anyone else could make use
of it, or wants to comment...)
Each child is another node, which in turn has its own children... So
effectively -children does represent the entire subtree.
You can traverse the whole thing like so:
@implementation NSXMLNode (Traversal)
- (void) traverse
{
NSObjectEnumerator* iter = [[self children] objectEnumerator];
NSXMLNode* node;
while(( node = [iter nextObject]))
{
// do something useful with the node here
// then recurse
[node traverse];
}
}
@end
Or have I misunderstood what you want?
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden