0

is it possible to write to an XML file that I've read from without using an external library ? I have read about writing using things KissXML, but I would like to write without anything extra.

So if I have an NSXMLElement or an NSXMLDocument in memory, how would I go about changing one of its nodes?

Thanks

Kevin
  • 1,469
  • 2
  • 19
  • 28

1 Answers1

2

Try to read apples docs at: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html#//apple_ref/doc/uid/TP40001269

  1. You need get node for change (using traverse tree or query node via XPath).
  2. Change node as you wish.

You can write xml data to file as a string after call XMLStringWithOptions for document.

PSyton
  • 908
  • 11
  • 18
  • If I have the XMLNode that I want to edit in memory, how can I change its value? I'm having some trouble understanding some terminology in the docs.. – Kevin Apr 23 '12 at 05:39
  • Ok so, if I have the following: NSXMLNode *xx = [descElements objectAtIndex:0]; NSLog (@"xx - %@", xx); [xx setStringValue: @"yy" ]; NSLog (@"(changed)xx - %@", xx); with descElements being an NSArray filled with Nodes, I can successfully change the value of a node. Now I want to write this single change to memory... Can that be done with XMLStringWithOptions? – Kevin Apr 23 '12 at 05:43
  • Just found that an NSXMLDocument will update automatically when its nodes will be changed, all that remains then is to save the document... Cool, makes things easier.. Thanks for your help! – Kevin Apr 23 '12 at 10:53