how to append tags in xml in iphone?
i am new developer in iphone application. i would like write a content in xml file for that, i have created xml file and write tags with element, attribute and value with some data in that xml as follows.
-(void)writexmlfile:(NSString *)data toFile:(NSString *)fileName NodeName:(NSString *)Node{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
NSString *fileExtension = [NSString stringWithFormat:@"%@%@",fileName,@".xml"];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileExtension];
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: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];
            XMLString = [[NSMutableString alloc]initWithString:docStr];
            [self XMLString];
            NSLog(@"data%@",XMLString);
        } 
    }
    // [XMLString insertString:data atIndex:index];
     [XMLString appendFormat:@"<%@>%@</%@> \n",Node,data,Node];
    BOOL success = [XMLString  writeToFile:appFile  atomically:YES encoding:NSUTF8StringEncoding error:&error];
    if (!success) {
        NSLog(@"Error: %@", [error userInfo]);
    }
    else {
        NSLog(@"File write is successful");
    }
}
}
i want add new tag with new elements,new attributes,etc.,if i enter element at the place of tag it is modifying with previous开发者_JS百科 tag .
here how can i append the new tag to previous appended tags
please any body could help me
Thanks in advance
As a suggestion, you can use APXML to create XML documents it is very simple and easy to use. This post can guide you further.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论