你能帮我处理这个程序吗?我正在尝试解析一个具有两个级别的 xml 文件(我不知道这个术语,所以我这样称呼)这是我的 xml 文件的示例
<?xml version="1.0" encoding="UTF-8"?>
<countries>
<country>
<countryname>Philippines</countryname>
<subsidiaries>
<subsidiary>
<name>Sart Philippines Inc.</name>
<address>Unit 10-A The World Empire Building, 330 Senator Gil Puyat Avenue Philippines, Philippines</address>
<phone>+63.2.929</phone>
<fax>+63.932</fax>
<email>enquiry.philippines@sarts.com</email>
<website>http://www.sartorius-mechatronics.com.ph</website>
</subsidiary>
</subsidiaries>
</country>
<country>
<countryname>Denmark</countryname>
<subsidiaries>
<subsidiary>
<name>Stedim Nordic A|S</name>
<address>Hoerskaetten 6d 2630 Taastrup, Denmark</address>
<phone>+45.7023.4400</phone>
<fax>+45.4630.4030</fax>
<email>ne.customersupport@sartorius.com</email>
<website></website>
</subsidiary>
<subsidiary>
<name>Nordic A|S</name>
<address>Hoerskaetten 6D 2630 Taastrup, Denmark</address>
<phone>+45.7523.8700</phone>
<fax>+45.4130.4020</fax>
<email>ne.customersupport@sartorius.com</email>
<website></website>
</subsidiary>
</subsidiaries>
</country>
</countries>
我打算做的是你选择一个国家,然后你选择一个子公司来查看它的信息。我能够解析它,但我无法展示 Stedim Nordic A|S 子公司。
这是我的解析器类
@implementation Parser
-(id)initParser
{
if (self == [super init])
{
app = (AppDelegate *) [[UIApplication sharedApplication]delegate];
}
return self;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"countries"])
{
app.listArray = [[NSMutableArray alloc]init];
}
if ([elementName isEqualToString:@"country"])
{
theList = [[List alloc]init];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!currentElementValue)
{
currentElementValue = [[NSMutableString alloc]initWithString:string];
}
else
{
[currentElementValue appendString:string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"country"])
{
[app.listArray addObject:theList];
}
else {
if ([elementName isEqualToString:@"countryname"]) {
theList.countryname = currentElementValue;
}
if ([elementName isEqualToString:@"name"])
{
theList.name = currentElementValue;
}
if ([elementName isEqualToString:@"address"])
{
theList.address = currentElementValue;
}
if ([elementName isEqualToString:@"phone"])
{
theList.phone = currentElementValue;
}
if ([elementName isEqualToString:@"fax"])
{
theList.fax = currentElementValue;
}
if ([elementName isEqualToString:@"email"])
{
theList.email = currentElementValue;
}
if ([elementName isEqualToString:@"website"])
{
theList.website = currentElementValue;
}
currentElementValue = nil;
}
}
@end
我不能很好地解释它,但我希望你能帮助我,如果你能给我发一个关于这类问题的教程的链接,我真的很感激