Edit and Save XML

DDenisska

New Member
Sorry for the rudimentary question - I need some help. I'm able to get the XML doc and save it. Can't get editing to work. I want to update the "theme" tag using the contents of a textField and set with an action prior to saving. My editing code obviously not working. Thanks for the help.-paul. \[code\] <temp><theme>note</theme> </temp> /////// NSMutableArray* temps = [[NSMutableArray alloc] initWithCapacity:10]; NSXMLDocument *xmlDoc; NSError *err=nil; NSString *file = [input1 stringValue]; NSURL *furl = [NSURL fileURLWithPath:file];if (!furl) { NSLog(@"Unable to create URL %@.", file); return;}xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options: (NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA) error:&err]; if (xmlDoc == nil) { xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:NSXMLDocumentTidyXML error:&err];} NSXMLElement* root = [xmlDoc rootElement]; NSArray* objectElements = [root nodesForXPath:@"//temp" error:nil];for(NSXMLElement* xmlElement in objectElements)[temps addObject:[xmlElement stringValue]]; NSXMLElement *themeElement = [NSXMLNode elementWithName:@"theme"];[root addChild:themeElement]; NSString * theTheme = [textField stringValue];[themeElement setStringValue:theTheme];\[/code\]
 
Back
Top