PDA

View Full Version : XML Parser




Monaj
Aug 28, 2009, 08:58 AM
Hello Everyone

I am using following method for fetch data from DB in form of XML
and using XML parser (http://www.keysoftwareservices.co.in/)

I calling this function in timer

It works fine

But some time application crashes due to this
Can any body tell me where i am wrong


-(void)parseXMLFileForUserId : ( NSString * )rolecode userId:(int)userId switchCase:( int )SCase lasTtime:(NSString * )lasTtime{

[eventsList removeAllObjects];
NSString *query;
NSString *stringBoundary,*contentType,*ans=@"123";
NSURL *cgiUrl;
NSMutableURLRequest *postRequest;
NSError *error;
NSData *searchData;
NSHTTPURLResponse *response;
NSMutableData *postBody;

switch (SCase) {
case 1:
query=[NSString stringWithFormat:@"Select distinct c.* from Calendar_Events as c , Cal_Delegates as d, rcs_update as r where c. calendar_id =d.calendar_id and d.role_code='%@' AND r.updated_entity_id=c.event_id and r.updated_entity='CALENDAR' and r.update_time >= '%@' AND NOT r.owner_id =%d AND NOT r.update_action='DEL' order by event_begin",rolecode,lasTtime,userId];
break;
case 2:
query=[NSString stringWithFormat:@"Select distinct r.updated_entity_id as event_id from rcs_update as r where r.updated_entity='CALENDAR' AND r.update_action = 'DEL' AND r.update_time >= '%@' AND NOT r.owner_id =%d",lasTtime,userId];
break;
default:
break;
}

NSLog(@"parseXMLFileForQueryEvents : %@",query);



cgiUrl = [NSURL URLWithString:@"https://keyss.in/API.php"];
postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
[postRequest setHTTPMethod:@"POST"];


stringBoundary = [NSString stringWithString:@"0000RCSIMGUploadxxxxxx"];
contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];

//setting up the body:
postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"code\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:ans] dataUsingEncoding:NSUTF8StringEncoding]];

[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"action\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"query"] dataUsingEncoding:NSUTF8StringEncoding]];

[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"devmode\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"devmode"]] dataUsingEncoding:NSUTF8StringEncoding]];

[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"q\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:query] dataUsingEncoding:NSUTF8StringEncoding]];

[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];

searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];

if([error code]!=0){
if(chkRetry<=3){
chkRetry++;
[self parseXMLFileForUserId:rolecode userId:userId switchCase:SCase lasTtime:lasTtime];
}
}
chkRetry=0;
eventsParser = [[NSXMLParser alloc] initWithData:searchData];
[eventsParser setDelegate:self];
[eventsParser setShouldResolveExternalEntities:YES];

BOOL success = [eventsParser parse];
[eventsParser release];
}



Thanks
Monaj



iShater
Aug 28, 2009, 09:04 AM
Please use the CODE tags around your code. It is the # symbol when you are editing/posting.

Monaj
Aug 28, 2009, 09:13 AM
sorry for that

rossipoo
Aug 28, 2009, 04:01 PM
That's a lot of code. Where exactly does it crash? You can check the console log or use the debugger to find out where it stops.

Monaj
Aug 31, 2009, 12:04 AM
there is no a particular position where its crashes
most of the it works ok

I am calling this function in every 25 second
some time its crashes in 10-25 min
some time after 1 -2 hour