Hii I am pretty much new to objective-C and got strucked at a particular point.. have to parse two XML files in a singleview and so I m using two NSXMLParsers to get it.But he proble m is one parser is getting recognized and second parser is not getting recognized..Y is it so ? I have written this :
The first parser is getting recognized and getting the data.But for the second parser didStartElement is not getting recognized...What could be the possible reason ?
Code:
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:Url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
[parser release];
NSXMLParser *parser1 = [[NSXMLParser alloc] initWithContentsOfURL:Url1];
[parser1 setDelegate:self];
[parser1 setShouldProcessNamespaces:NO];
[parser1 setShouldReportNamespacePrefixes:NO];
[parser1 setShouldResolveExternalEntities:NO];
[parser1 parse];
[parser1 release];
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"TimeList"])
{
arr1=[[NSMutableArray alloc] init];
drr1=[[NSMutableDictionary alloc] init];
}
if([elementName isEqualToString:@"Company"])
{
drr1=[[NSMutableDictionary alloc] init];
}
srr1=[[NSMutableString alloc] init];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{ [srr1 appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"ID"])
{
[drr1 setObject:srr1 forKey:@"ID"];
[srr1 release],srr1=nil; return;
}
if([elementName isEqualToString:@"Company"])
{
[arr1 addObject:drr1];
}
if([elementName isEqualToString:@"TimeList"])
{
[drr1 release];
}
[srr1 release],srr1=nil;
}
- (void)parser1:(NSXMLParser *)parser1 didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"categorylist"])
{
arr2=[[NSMutableArray alloc] init];
drr2=[[NSMutableDictionary alloc] init];
}
if([elementName isEqualToString:@"lookup"])
{
drr2=[[NSMutableDictionary alloc] init];
}
srr2=[[NSMutableString alloc] init];
}
-(void)parser1:(NSXMLParser *)parser1 foundCharacters:(NSString *)string
{
[srr2 appendString:string];
}
- (void)parser1:(NSXMLParser *)parser1 didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"Code"])
{
[drr2 setObject:srr2 forKey:@"Code"];
[srr2 release],srr2=nil;
return;
}
if([elementName isEqualToString:@"lookup"])
{
[arr2 addObject:drr2];
}
if([elementName isEqualToString:@"categorylist"])
{
[drr2 release];
} [srr2 release],srr2=nil;
}