sqlite 导出为 XML格式

- (IBAction)create:(id)sender
{
NSXMLElement *xmlelement = [NSXMLNode elementWithName:@"vote"];///////////////根结点
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithRootElement:xmlelement];
for(int i =0; i < 4;i++){
NSXMLElement*stu = [NSXMLNodeelementWithName:@"Student \n"];
NSXMLElement*stuid = [NSXMLNodeelementWithName:@"StudentID"];
NSXMLElement*stuname = [NSXMLNodeelementWithName:@"StudentNo"];
NSXMLElement*stutel = [NSXMLNodeelementWithName:@"LastName"];
NSXMLElement*contact = [NSXMLNodeelementWithName:@"contact"];
NSXMLElement *contactname = [NSXMLNode elementWithName:@"Contactnsme"];
NSXMLElement *contactsex = [NSXMLNode elementWithName:@"ContactSex"];
[xmlelement addChild:stu];
[stu addChild:stuid];
[stu addChild:stuname];
[stu addChild:stutel];

[stu addChild:contact];
[contact addChild:contactname];
[contact addChild:contactsex];

NSArray *arrid = [stu elementsForName:@"StudentID"];
NSArray *arrname = [stu elementsForName:@"StudentNo"];
NSArray *arrtel = [stu elementsForName:@"LastName"];
NSArray *arrconname = [contact elementsForName:@"Contactnsme"];
[[arrconname objectAtIndex:0] setStringValue:@"hsdakhsjkahdkjsad"];////////在此给每个字段填冲数据
}
[doc setVersion:@"1.0"];
[doc setCharacterEncoding:@"UTF-8"];

NSData *xmldata = doc.XMLData;
NSSavePanel*oPanel = [NSSavePanelsavePanel];
NSString*startingDir = [[NSUserDefaultsstandardUserDefaults] objectForKey:@"StartingDirectory"];
    if (!startingDir)
        startingDir = NSHomeDirectory();
NSString *str = [oPanel title];


if([oPanel runModalForDirectory:startingDir file:str] == NSOKButton)
{
NSLog(@"ok");
}
NSString *filename = [oPanel filename];
filename =[filename stringByAppendingString:@".xml"];


NSLog(@"%@",filename);
[xmldata writeToFile:filename atomically:YES];
}

你可能感兴趣的:(xml,数据库,sqlite,职场,休闲)