Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cblackburn

macrumors regular
Original poster
Jul 5, 2005
158
0
London, UK
Hey all,

I have followed the guide at http://developer.apple.com/document...L_Concepts/Articles/UsingTreeControllers.html as to setting up an NSBrowser backed by an XML File. Très cool btw, saves a *lot* of code and give you a load of flexibility, however...

At the moment it decides whether or not an item is a leaf (end of the tree structure) by checking to see if it is an element or not, if not then it assumes it is a leaf. I want it to behave a little differently however. I want it to Leaf one step up from the end of the XML structure. That way I can give attributes to each leaf that I can read in Cocoa Bindings.

If anyone has any ideas on how to go about doing this, or any better ideas as to how I should do it completely differently, I'm all ears :)

Chris
 

cblackburn

macrumors regular
Original poster
Jul 5, 2005
158
0
London, UK
*slaps forehead* d'oh, that was easier than I thought. I didn't realise that NSXMLNode was aware of structure I thought they were completely independent and needed the NSXMLDocument to tie them together. In the end the isLeaf code looks like this:-

Code:
- (BOOL)isLeaf 
{
	BOOL isLeaf = YES;
    NSArray * theChildren = [self children];
	NSEnumerator * theEnumerator = [theChildren objectEnumerator];
	NSXMLNode * child;
	
	while(child = [theEnumerator nextObject])
	{
		if([child childCount] > 0)
			isLeaf = NO;
	}
	
	return isLeaf;
}

Works like a charm :-D

Chris
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.