I am new to iPhone programming and I am using NSXmlParser to parse the data and store it in an array but I have 3 tables data I want to store that in 3 different arrays, can anybody tell me how can I parse the data and store it in 3 different array.
My xml looks like this
<Result>
<Table diffgr:id="Table1" msdata:rowOrder="0">
<CreatedBy>1</CreatedBy>
<Email>YOURMAIL1@CAFE.COM</Email>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="0">
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL2@CAFE.COM</Email>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="0">
<CreatedBy>3</CreatedBy>
<Email>YOURMAIL3@CAFE.COM</Email>
<SalesAmount>0.0000</SalesAmount>
<PurchasesAmount>0.0000</PurchasesAmount>
</Table>
</Result>
Using below code I am able to store all parsed data in one array.
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
arr_info=[NSMutableArray arrayWithObjects:@"CreatedBy",@"Email",@"SalesAmount",@"PurchasesAmount",nil];
for (i=0; i<[arr_info count]; i++)
{
if( [elementName isEqualToString:[arr_info objectAtIndex:i]])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( xmlResults )
{
[soapResults appendString: string];
NSLog(@"soap result %@",soapResults);
[arr_detail addObject:soapResults];
NSLog(@"gg %@",arr_detail);
}
[tableView reloadData];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
for (i=0; i<[arr_info count]; i++)
{
if( [elementName isEqualToString:[arr_info objectAtIndex:i]])
{
xmlResults = FALSE;
switch ([arr_detail count]) {
case 1:
l1.text=[arr_detail objectAtIndex:[arr_detail count]-1];
NSLog(@"%@",[arr_detail objectAtIndex:[arr_detail count]-1]);
break;
case 2:
l2.text=[arr_detail objectAtIndex:[arr_detail count]-1];
NSLog(@"%@",[arr_detail objectAtIndex:[arr_detail count]-1]);
break;
case 3:
l3.text=[arr_detail objectAtIndex:[arr_detail count]-1];
NSLog(@"%@",[arr_detail objectAtIndex:[arr_detail count]-1]);
break;
case 4:
l4.text=[arr_detail objectAtIndex:[arr_detail count]-1];
NSLog(@"%@",[arr_detail objectAtIndex:[arr_detail count]-1]);
break;
}
[tableView reloadData];
soapResults = nil;
}
}
}