PDA

View Full Version : NSXMLNode Stuff




cblackburn
Jun 27, 2007, 06:37 AM
Hey all,

I have followed the guide at http://developer.apple.com/documentation/Cocoa/Conceptual/NSXML_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
Jun 27, 2007, 06:45 AM
*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:-

- (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