简体   繁体   中英

How to write XML file with data from text fields

I am creating a project in which I have three UITextField s and one UIButton . Now on text fields I have function that user give input. I define a target-action on button press which needs to save the values of the text fields in an XML file. How do I create an xml file and save all the data in xml file with unique ID?

-(IBAction)Submit:(id)sender{
    if([txtPhone.text length] == 0 || [txtPhone.text isEqualToString:@""] && [txtName.text length] == 0 || [txtName.text isEqualToString:@""] && [txtEmail.text length] == 0 || [txtEmail.text isEqualToString:@""] )
    {
        UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message: @"Please fill the form." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [info show];
        [info release]; 
    }
    else {
        sixthView=[[SixthView alloc] initWithNibName:@"SixthView" bundle:nil];
        [self.navigationController pushViewController:self.sixthView animated:YES];
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
    }
}

The XSWI project hosts a simple, standalone XML stream writer for iOS implemented in Objective-C . As such, it can be used for iPhone, iPad and iPod apps.

you could get the source code from github project .

check the SO post for creating an XML request in iPhone.

Why do you want to use XML? I recommend you to use CSV, its simpler and then export a CSV to iTunes. I have posted a code in my blog here about how to export a file to iTunes http://alwawee.com/wordpress/?p=429 . To generate unique name you can use current date in addition to some file name or use id, that is stored in NSUserDefaults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM