Skip to content

Instantly share code, notes, and snippets.

@wujun
Created February 19, 2012 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wujun/1862295 to your computer and use it in GitHub Desktop.
Save wujun/1862295 to your computer and use it in GitHub Desktop.
parser xml file
- (void)parseData
{
//self.importCardArray = [NSMutableArray arrayWithCapacity:10];
[self.xmlParser setDelegate:self];
self.statusLabel.text= @"Storing the cards to the database...";
BOOL xmlParsingOK = [self.xmlParser parse];
if (xmlParsingOK) {
self.statusLabel.text= @"All entry successfully imported.";
}
else
{
self.statusLabel.text= @"Error parsing the xml file.";
}
self.spinner.hidden= YES;
[self.spinner stopAnimating];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
// Parsing the header record for the subject information
if ([elementName isEqualToString:@"subject"]) {
self.importSubjectID = [attributeDict valueForKey:@"subjectID"];
self.importSubjectDescription = [attributeDict valueForKey:@"subjectDescription"];
self.customDictionaryURL = [attributeDict valueForKey:@"customDictionaryURL"];
...my property assignments etc
}
// Parsing the header record for the locale information
if ([elementName isEqualToString:@"locale"]) {
...my property assignments etc
}
// Parsing the question and answers
if ([elementName isEqualToString:@"Entry"]) {
NSString *myQuestion = [attributeDict valueForKey:@"question"];
NSString *myAnswer = [attributeDict valueForKey:@"answer"];
NSString *myEntryType = [attributeDict valueForKey:@"entryType"];
...my property assignments etc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment