PDA

View Full Version : NSXMLElement and NSXMLNode




CKriens
Jun 9, 2009, 11:39 PM
I've got an NSXMLDocument providing hierarchical data to a NSOutline view instance using the standard Data Source technique. I would like the user to be able to remove the lowest level elements from this document by selecting an object and activating a button. I've connected a button to this method:

- (IBAction)deleteDisplay:(id)sender {
/*** Find the current selected element ***/
NSXMLElement *selected = [outlineView itemAtRow:[outlineView selectedRow]];

/*** Commit its id value to memory ***/
int identifier = [[[selected attributeForName:@"id"] objectValue] intValue];

/*** Navigate up one level and remove the element ***/
[[selected parent] removeChildAtIndex:identifier];

[outlineView reloadData];
}


This code successfully links up to the correct object and moves back up to its parent. The problem occurs when I try to use removeChildAtIndex:, which is a method for NSXMLElement whereas the parent method returns an NSXMLNode.

It seems that in order to accomplish this, I need to use methods from both of these classes, but run into issues because they're not translating. Is there a way to make my NSXMLNode into an NSXMLElement? Maybe there's an alternative way to reach the parent node of my element that avoids the NSXMLNode class all together? This seems like a trivial problem, so I must be missing something.

Thanks in advance!