Many NSXMLParsers in a singleview xcode

Many NSXMLParsers in a singleview xcode

arizah

New Member
Thread Starter
Joined
Oct 12, 2012
Messages
6
Reaction score
0
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 :

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;     
}
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 ?
 
Would you be so kind and explain what you mean by "Not getting recognized". Are you speaking about a compiler error, runtime error or lack of functionality once the code is running?
 
I m not getting any error..I mean after the debugger passes this line [parser1 parse] it should go to the delegates didStartElement,foundcharacters and didEndElement but in my case the debugger is not entering those delegates.It is simply jumping to [parser1 release] stmnt.So those delegates are not getting recognized for parser1..How can I fix it?
 
Since you haven't pasted all the code, which I don't suggest, I can't really tell where the real error is coming from. But I can show you a simple trick in debugging techniques to help troubleshoot the issue yourself.

Change the following line of code and then run the application in debug mode.

Code:
  NSXMLParser *parser1 = [[NSXMLParser alloc] initWithContentsOfURL:Url1];
to
Code:
  NSXMLParser *parser1 = [[NSXMLParser alloc] initWithContentsOfURL:Url];

If it starts working as expected then the issue is with Url1 not the code you have pasted. If it doesn't work then I will show you the next test to run.
 
But I have two different urls to get the response ..
 
That is correct. But you are trying to find a program error. To do that, you must use a known good piece of code. So please make the change and test the code so I can help you.

I have been programming for 32 years. 28 of them professionally. I am very good at it. So please have a little faith that I know what I am doing.
 

Latest posts

Back
Top