我解析XML文件和我的XML看起來像:如何在iphone中解析XML時添加多個相同的XML標記?
<List>
<CompanyallProvidersList>
<CityDetails>
<City>NewYork</City>
<Id>1</Id>
</CityDetails>
<StateDetails>
<State>Alabaster</State>
</StateDetails>
<CityDetails>
<City>Newyork</City>
<Id>1</Id>
</CityDetails>
<StateDetails>
<State>California</State>
</StateDetails>
</CompanyallProvidersList>
</List>
我的解析器代碼是這樣的:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"CompanyallProvidersList"])
{
arr=[[NSMutableArray alloc] init];
drr=[[NSMutableDictionary alloc] init];
}
srr=[[NSMutableString alloc] init];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
[srr appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"City"])
{
[drr setObject:srr forKey:@"City"];
[srr release],srr=nil;
return;
}
if([elementName isEqualToString:@"Id"])
{
[drr setObject:srr forKey:@"Id"];
[srr release],srr=nil;
return;
}
if([elementName isEqualToString:@"State"])
{
[drr setObject:srr forKey:@"State"];
[srr release],srr=nil;
return;
}
if([elementName isEqualToString:@"CompanyallProvidersList"])
{
[arr addObject:drr];
[drr release],drr=nil;
}
[srr release],srr=nil;
}
我的輸出是這樣的:
NewYork
1
California
但我想輸出爲:
NewYork
1
Alabaster
NewYork
1
California
`我無法得到它..我哪裏錯了?
任何幫助,將不勝感激......
感謝....
嘿感謝Midhun ....我it..Yahoooo !!!! +100如果可能... – cutiepie
@cutiepie:高興:) –
@Mithun。我有一個小問題,我得到這樣的:({City =「NewYork」; Id =「1」; State = Alabaster;} {如何刪除所有這些({「;從響應和顯示在一個TableView與2行? – cutiepie