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:
And the code Iam writing for parsing is :
The result I could see in arr1
I could not see the last value.How can I get all the items ?
Code:
<IDList>
<Employee>
<ID>1</ID>
</Employee
<Employee>
<ID>2</ID>
</Employee>
<Employee>
<ID>3</ID>
</Employee>
<Employee>
<ID>4</ID>
</Employee>
</IDList>
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;
}
Code:
(
{ ID="1",
}
{ ID="2",
}
{ ID="3",
}
{ ID="",
}
)