我是电话编程的新手。我有如下所示的 xml 数据。使用该数据我想显示具有 2 个表的特定日期数据,如何在单行中显示特定日期数据。在下一个数据 2012-06- 20 有 3 个表我如何在第二行显示 3 个表数据。我如何解析该数据,告诉我逻辑
<Result>
<Table diffgr:id="Table1" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>1</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>100.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>1</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>100.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table3" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table4" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table5" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T11:01:54-06:00</CafeDateTime>
<CreatedBy>2</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>200.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table6" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T09:01:54-06:00</CafeDateTime>
<CreatedBy>3</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>150.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Table> <Table diffgr:id="Table7" msdata:rowOrder="2">
<CafeDateTime>2012-09-19T10:01:54-06:00</CafeDateTime>
<CreatedBy>3</CreatedBy>
<Email>YOURMAIL@CAFE.COM</Email>
<AdminPassword>admin1</AdminPassword>
<SalesDailyAmount>150.0000</SalesDailyAmount>
<PurchasesDailyAmount>0.0000</PurchasesDailyAmount>
</Table>
</Result>
2012-09-19 ->Having 2 tables(i.e Table1,Table2)
2013-09-20 ->Having 3 tables(i.e Table3,Table4,Table5)
2013-09-21 ->Having 2 tables(i.e Table6,Table7)
现在我的问题是在上面的 xml 数据中,我在 table1 中共有 7 个表,table2 数据属于 2012-09-19 日期。我想解析数据并显示在下面的视图中
CreateBy SalesDailyAmount PurchasesDailyAmount
2012-09-19 ->Want to display 1 100 0.0000
使用下面的代码
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
if( [elementName isEqualToString:@"CreateBy"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
if( [elementName isEqualToString:@"SalesDailyAmount"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
if( [elementName isEqualToString:@"PurchasesDailyAmount"])
{
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);
NSLog(@"gcvxg %@",arr_info);
}
[tableView reloadData];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"CreateBy"])
{
xmlResults = FALSE;
[aslam4 addObject:soapResults];
NSLog(@"hello %@",aslam4);
soapResults = nil;
}
if( [elementName isEqualToString:@"SalesDailyAmount"])
{
xmlResults = FALSE;
[aslam5 addObject:soapResults];
NSLog(@"hello %@",aslam5);
soapResults = nil;
}
if( [elementName isEqualToString:@"PurchasesDailyAmount"])
{
xmlResults = FALSE;
[aslam6 addObject:soapResults];
NSLog(@"hello %@",aslam6);
soapResults = nil;
}
}
}
使用上面的代码,我可以得到如下数据
OutPut
CreateBy SalesDailyAmount PurchasesDailyAmount
1 100 0.0000
1 100 0.0000
2 200 0.0000
2 200 0.0000
2 200 0.0000
3 150 0.0000
3 150 0.0000
但我想在下面显示这样
CreateBy SalesDailyAmount PurchasesDailyAmount
2012-09-19 ->Want to display 1 100 0.0000
2012-09-20 ->Want to display 2 200 0.0000
2012-09-21 ->Want to display 3 150 0.0000
我不想显示多次。在 2012 年 9 月 19 日有 2 个表,但都有相同的数据,但我不想显示多次。同样,2012-09-20 在这里有 3 个表,我也不想显示 3 次,我想在一行中显示 3 个表数据。总的来说,我想说的是,现在在数组中它的存储数据如下 Array ={100,100,200,200,200,150,150} 但我不想这样我想像这样存储 Array ={100,200,150} 可以请告诉我如何为此编写逻辑.