how to save and update value in xml file in iphone?
<p>I am a new iphone develaper.i am reading a xml file. Here I want to write the xml file and I want to change the values of the XML file and I want to save the file..</p>

<p>My code is like below...... Please guide me how to save and update value in xml file... </p>

<pre><code>-(void)writexmlfile:(NSString *)data toFile:(NSString *)fileName nodename:(NSString *)nodename{


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    // the path to write file
    NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml",fileName]];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:appFile];
    if(fileExists) {
        NSError *error = nil;
        NSString *docStr;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        // the path to write file
        NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml",fileName]];

        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:appFile];
        if(fileExists)
        {
            NSLog(@"file exist in document");
            NSData *myData1 = [NSData dataWithContentsOfFile:appFile];
            if (myData1) {  
                docStr = [[NSString alloc] initWithData:myData1 encoding:NSASCIIStringEncoding];

            } 
        }
        NSMutableString *str = [[NSMutableString alloc] init];
        NSString *aaa=[NSString stringWithFormat:@" &lt;%@&gt;%@&lt;/%@&gt;",nodename,data,nodename];
        [str appendString:docStr];

        [str insertString:aaa atIndex:70];
        BOOL success = [str writeToFile:appFile  atomically:YES encoding:NSUTF8StringEncoding error:&amp;error];
        if (!success) {
            NSLog(@"Error: %@", [error userInfo]);
        }
        else {
            NSLog(@"File write is successful");
        }
    }
}
</code></pre>
