I have a problem which probably is a logical one. I have a tree representing nodes of a simple XML document. Actually, what it represents is pretty irrelevant to my problem.
I want to be able to represent these data (which is plain text) into an NSBrowser. Although I fail to see how can I traverse the tree and represent those nodes. I have chosen the passive implementation of the tree, since it's easier. This is what my delegate does:
Note that countSiblings is a function created by me that count's a node's siblings. Anyway , how am I going to do this? I need just a method, not necessarily code. Any help would be appreciated.
I want to be able to represent these data (which is plain text) into an NSBrowser. Although I fail to see how can I traverse the tree and represent those nodes. I have chosen the passive implementation of the tree, since it's easier. This is what my delegate does:
Code:
@interface GeneralHandler : NSObject {
NSXMLDocument *doc;
NSXMLNode *currentNode;
}
@end
@implementation GeneralHandler
-(void)awakeFromNib
{
NSLog([[self class]description]);
NSString *xmlContents = [NSString stringWithContentsOfFile:[[NSString stringWithString:@"~/Desktop/info.xml"]stringByStandardizingPath]];
doc = [[NSXMLDocument alloc]initWithXMLString:xmlContents options:NSXMLDocumentTidyXML error:nil];
NSLog([[doc rootElement]name]);
currentNode = [doc rootElement];
}
- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column {
if (column == 0) {
return 1;
}
return [currentNode countSiblings];
}
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column {
// Find our parent FSNodeInfo and access the child at this particular row
[cell setStringValue:[currentNode name]];
currentNode = [currentNode childAtIndex:row];
}
@end
Note that countSiblings is a function created by me that count's a node's siblings. Anyway , how am I going to do this? I need just a method, not necessarily code. Any help would be appreciated.