NSXMLParserDelegate methods are not called

CSS.Xml

New Member
Hi iam parsing an xml file and i got the response also which i have stored in a responseString.My problem with the delegate methods which are not being called, here's my parsing code \[code\] -(void)getData{ NSURL *url = [NSURL URLWithString:@"http://quizpro.testshell.net/api/quiz/4"]; NSData *data = http://stackoverflow.com/questions/13739200/[NSData dataWithContentsOfURL:url]; // Load XML data from web NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"quiz.xml"]; NSLog(@"store path is %@",storePath); [data writeToFile:storePath atomically:TRUE];ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];request.delegate=self;[request startSynchronous];NSError *error = [request error];if (!error){ NSData *responseData=http://stackoverflow.com/questions/13739200/[request responseData]; NSString *data =[[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding] autorelease]; NSString *usableXmlString = [data stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSLog(@"usableXmlString is %@",usableXmlString); NSData *usableData = http://stackoverflow.com/questions/13739200/[usableXmlString dataUsingEncoding:NSUTF8StringEncoding]; NSXMLParser *xmlParser = [[NSXMLParser alloc]initWithData:usableData]; [xmlParser setDelegate:self]; [xmlParser parse];} } - (void)requestFinished:(ASIHTTPRequest *)request{NSLog(@"requestFinished method");// Use when fetching textNSString *responseString = [request responseString]; ** I get the entire data here ** NSLog(@"responseString is %@",responseString);NSData *xData = http://stackoverflow.com/questions/13739200/[responseString dataUsingEncoding:NSUTF8StringEncoding];//myCode.text = responseString;//NSLog(@" response %@", responseString);NSXMLParser *parser = [[NSXMLParser alloc] initWithData:xData];[parser setDelegate:self];[parser parse];[parser release];}\[/code\]And i wrote the NSXMLParser delegate methods like below \[code\]-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { NSLog(@"parser/didStartElement"); currentTag = elementName; if ([currentTag isEqualToString:@"questions"]) { exams_object=[[ExamsObject alloc]init]; NSLog(@"%@",currentTag); } if ([currentTag isEqualToString:@"Question"]) { exams_object=[[ExamsObject alloc]init]; } if ([currentTag isEqualToString:@"Response"]) { exams_object.responseArray=[[NSMutableArray alloc]init]; } NSLog(@"%@",currentTag); } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { NSLog(@"parser/didEndElement"); if ([currentTag isEqualToString:@"questions"]) { exams_object=[[ExamsObject alloc]init]; } if([elementName isEqualToString:@"Question"]) { [mainArray addObject:exams_object]; } } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)str { NSLog(@"parser/foundCharacters"); if ([currentTag isEqualToString:@"questionText"]) { [exams_object.questionArray addObject:str]; } if ([currentTag isEqualToString:@"responseText"]) { [exams_object.responseArray addObject:str]; } } \[/code\]Thanks for help me
 
Back
Top