XMLParser repeating elements on iphone

Maseonary

New Member
I have an NSXMLParser, which is parsing an XML file, using apple's implementation of event-driven XML handling.I have it setup correctly, but when I get to the actual parsing, it goes over the same element twice as it parses through.My code looks like this:\[code\]AppDelegate *myApp = (AppDelegate*)[[UIApplication sharedApplication] delegate];NSData *tempData = http://stackoverflow.com/questions/12682189/[myApp.stringDetails dataUsingEncoding:NSUTF8StringEncoding];NSString *textFields = [NSString string];NSXMLParser *parser = [[NSXMLParser alloc]initWithData:tempData];[parser setDelegate: self];if ([parser parse]!= YES){ NSLog(@"%@", parser.parserError.description);}}- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"%@", elementName); textFields = elementName;}- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if ([textFields isEqualToString:@"firstName"]) { [firstName setText:string]; NSLog(@"first name is %@", string); return; } if([textFields isEqualToString:@"lastName"]) { [lastName setText:string]; NSLog(@"last name is %@", string); return; }}- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ return;}\[/code\]The XML document i'm parsing looks like this:\[code\]<details><firstName>tester</firstName> <lastName>testingson</lastName> <address> <street1>123 Main St.</street1> <street2></street2> <city>Anywhere</city> <state>BC</state> <country></country> <postalCode>A0A0B0</postalCode></address><company>TEST</company><email>[email protected]</email><cabbieNo>TEST</cabbieNo><driversLicense>TEST</driversLicense><plateNo>TEST</plateNo> <services> <taxi>1</taxi> <ladies>1</ladies> <limo>1</limo> <handicap>1</handicap></services></details>\[/code\]Strangely, my debug logs like this:\[code\]2012-10-01 15:36:35.742 myAPP[9974:c07] first name is tester2012-10-01 15:36:35.743 myAPP[9974:c07] first name is2012-10-01 15:36:35.743 myAPP[9974:c07] last name is testingson2012-10-01 15:36:35.744 myAPP9974:c07] last name is \[/code\]as you can see, it looks through each element twice, but then on the second time, \[code\]string\[/code\] is empty (which shouldn't happen..in fact there shouldn't even be a second \[code\]foundCharacters\[/code\] event). Do you guys have any idea why? Thanks!
 
Back
Top