- (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 = [NSXMLNode@"StudentID"*stuname = [NSXMLNode@"StudentNo"*stutel = [NSXMLNode@"LastName"*contact = [NSXMLNode@"contact"];
NSXMLElement *contactname = [@"Contactnsme"];
NSXMLElement *contactsex = [@"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 @"StudentNo"];
NSArray *arrtel = [stu @"LastName"];
NSArray *arrconname = [contact @"Contactnsme"];
[[arrconname objectAtIndex:0] setStringValue@"hsdakhsjkahdkjsad"];////////在此给每个字段填冲数据
}
[doc setVersion@"1.0"];
[doc setCharacterEncoding@"UTF-8"];
NSData *xmldata = doc.XMLData;
NSSavePanel*oPanel = [NSSavePanelsavePanelNSString*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"];
@"%@",filename);
[xmldata writeToFile:filename atomically:YES]; }