Adding XML parsed data to NSMutableArray in iPhone?

Adding XML parsed data to NSMutableArray in iPhone?

arizah

New Member
Thread Starter
Joined
Oct 12, 2012
Messages
6
Reaction score
0
I am parsing XML response and adding it to NSMutableArray.The problem islast value of XML response is not getting added to NSMutableArray..Couldn't get where I am going wrong? My XML file looks like this:

Code:
<IDList> 
              <Employee>   
                    <ID>1</ID>  
              </Employee  
              <Employee>  
                   <ID>2</ID> 
              </Employee>  
              <Employee> 
                   <ID>3</ID> 
              </Employee>  
              <Employee>  
                  <ID>4</ID> 
              </Employee>
         </IDList>
And the code Iam writing for parsing is :
Code:
[COLOR=#000000][FONT=Consolas]- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{[/FONT][/COLOR]
 if([elementName isEqualToString:@"IDList"]) 
{ 
arr1=[[NSMutableArray alloc] init]; 
drr1=[[NSMutableDictionary alloc] init];
 } 
if([elementName isEqualToString:@"Employee"]) 
{ 
 drr1=[[NSMutableDictionary alloc] init];         
}
 srr1=[[NSMutableString alloc] init];
 }

Code:
-(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:@"Employee"]) 
{ 
[arr1 addObject:drr1]; 
} 
if([elementName isEqualToString:@"IDList"]) 
{
 [drr1 release]; 
} 
[srr1 release],srr1=ni; 
}
The result I could see in arr1

Code:
(   
 {      ID="1",  
  }    
{      ID="2",   
 }  
  {      ID="3",    
}    
{      ID="",    
}  
 )
I could not see the last value.How can I get all the items ?
 

Latest posts

Back
Top