title: XCODE NSXML changing the element value
body: <p>I have a very simple xml file by name options.xml</p>
  
  <pre><code>&lt;Dat&gt;
      &lt;Name&gt;Tom&lt;/Name&gt;
      &lt;Option&gt;1&lt;/Option&gt;
  &lt;/Dat&gt;
  </code></pre>
  
  <h2>Using NSXML I am trying to change "Tom" to "Jim" and save the file. How can I do that. I read many document and there is no straight forward solution. Can some one help me with the code ?</h2>
  
  <p>update: I ended up in trying with Gdatasxml</p>
  
  <pre><code> -(void)saveToXML
  {
  NSString* path = [[NSBundle mainBundle] pathForResource:@"options" ofType:@"xml"];
  
  NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:path];
  NSError *error;
  GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&amp;error];
  
  GDataXMLElement *rootElement = [GDataXMLElement elementWithName:@"Dat"];
  
  NSArray *mySettings = [doc.rootElement elementsForName:@"Dat"];
  
  for (GDataXMLElement *mySet in mySettings)
  {
      NSString *name;
      NSArray *names = [mySet elementsForName:@"Name"];
      if (names.count &gt; 0)
      {
          GDataXMLElement *childElement = (GDataXMLElement *) [names objectAtIndex:0];
          name = childElement.stringValue;
          NSLog(childElement.stringValue);
          [childElement setStringValue:@"Jim"];
      } 
  }
  
  [xmlData writeToFile:path atomically:YES];
  
  
  }
  </code></pre>
  
  <p>But this is not saving the data. Help.</p>