Problem with writeData

Posted by zp26 on Stack Overflow See other posts from Stack Overflow or by zp26
Published on 2010-05-31T14:19:42Z Indexed on 2010/05/31 14:23 UTC
Read the original article Hit count: 393

Filed under:
|
|

Hi, I have a problem with my code. I want to create a XML file like this:

<name>myName<name>
 <x>myX<x>
 <y>myY<y>
 <z>myZ<z>

but my file is:

<name>myName<name><x>myX<x><y>myY<y><z>myZ<z>

Can i have this text formatting? This is my code:

-(void)salvataggioInXML:(NSString*)name:(float)x:(float)y:(float)z{

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES);
 NSString *documentsDirectoryPath = [paths objectAtIndex:0];
 NSString *filePath = [documentsDirectoryPath  stringByAppendingPathComponent:@"filePosizioni.xml"];
 NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
 [myHandle seekToEndOfFile];

 NSString *tagName = [NSString stringWithFormat:@"<name>%@<name>", name];
 NSString *tagX = [NSString stringWithFormat:@"<x>%f<x>", name];
 NSString *tagY = [NSString stringWithFormat:@"<y>%f<y>", name];
 NSString *tagZ = [NSString stringWithFormat:@"<z>%f<z>", name];

 NSData* dataName = [tagName dataUsingEncoding: NSASCIIStringEncoding];
 NSData* dataX = [tagX dataUsingEncoding: NSASCIIStringEncoding];
 NSData* dataY = [tagY dataUsingEncoding: NSASCIIStringEncoding];
 NSData* dataZ = [tagZ dataUsingEncoding: NSASCIIStringEncoding];

 [myHandle writeData:dataName];
 NSLog(@"writeok");

 [myHandle seekToEndOfFile];
 [myHandle writeData:dataX];
 NSLog(@"writeok");

 [myHandle seekToEndOfFile];
 [myHandle writeData:dataY];
 NSLog(@"writeok");

 [myHandle seekToEndOfFile];
 [myHandle writeData:dataZ];
 NSLog(@"writeok");

 [myHandle seekToEndOfFile];

 NSLog(@"zp26 %@",filePath);


}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c