In my iPAD application, I call a webservice to get a XML response, then I parse it and store it into my SQLITE database.
The parsing and saving are happening properly, but the problem I am having is that it is taking a very long time for it to perform the operation.
Using the mac, I saw the number of records being saved to the database. It was 395 rows where each row has 8 columns in it i.e. around 3100 records are being stored to my database.(my entity has 8 attributes in it). On the iPAD, it takes about 25 seconds to do the whole operation, which I was told is too long. I am unable to figure out why it is taking so long and where I am going wrong.
This is the code which I use for parsing the XML and storing -
It would be great if someone could help me out with this and tell me if something is wrong with the way I am parsing and saving.
The parsing and saving are happening properly, but the problem I am having is that it is taking a very long time for it to perform the operation.
Using the mac, I saw the number of records being saved to the database. It was 395 rows where each row has 8 columns in it i.e. around 3100 records are being stored to my database.(my entity has 8 attributes in it). On the iPAD, it takes about 25 seconds to do the whole operation, which I was told is too long. I am unable to figure out why it is taking so long and where I am going wrong.
This is the code which I use for parsing the XML and storing -
Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"return"])
{
// Blank lab panel object
objLabPanel = [NSEntityDescription insertNewObjectForEntityForName:@"LabPanels" inManagedObjectContext:managedObjectContext];
mainElement = elementName;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
elementValue = [[NSMutableString alloc] init];
[elementValue appendString:string];
// Handle html codes
elementValue = [CommonHelper encodeHTMLCharactorsForDataBaseStorage:elementValue];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"return"])
{
[objPatient addLabPanelsObject:objLabPanel];
// Save
NSError *error = nil;
BOOL saveObj = FALSE;
saveObj = [managedObjectContext save:&error];
if (saveObj == FALSE)
{
NSLog (@"Error: %@", error);
}
}
else if ([elementName isEqualToString:@"batteryID"] && [mainElement isEqualToString:@"return"])
{
objLabPanel.labPanelBatteryId = elementValue;
}
else if ([elementName isEqualToString:@"batteryVersionNum"] && [mainElement isEqualToString:@"return"])
{
objLabPanel.labBatteryVersionId = elementValue;
}
else if ([elementName isEqualToString:@"conceptCode"] && [mainElement isEqualToString:@"return"])
{
objLabPanel.labPanelCode = elementValue;
}
else if ([elementName isEqualToString:@"conceptDescription"] && [mainElement isEqualToString:@"return"])
{
objLabPanel.labPanelDesc = elementValue;
}
else if ([elementName isEqualToString:@"effectiveEndTime"] && [mainElement isEqualToString:@"return"])
{
endDate = [CommonHelper getDateFromXMLString:[NSString stringWithString:elementValue] :@"yyyy-MM-dd'T'HHmmssZ"];
objLabPanel.labPanelEndDate = endDate;
}
else if ([elementName isEqualToString:@"effectiveStartTime"] && [mainElement isEqualToString:@"return"])
{
startDate = [CommonHelper getDateFromXMLString:[NSString stringWithString:elementValue] :@"yyyy-MM-dd'T'HHmmssZ"];
objLabPanel.labPanelStartDate = startDate;
}
else if ([elementName isEqualToString:@"body"])
{
// Release all variables at the end of xml parsing
[self releaseVariables];
}
elementValue = nil;
It would be great if someone could help me out with this and tell me if something is wrong with the way I am parsing and saving.