I'm having a hard time displaying my xml in my tableview. I parse it successfully using NSXMLparser but when i am retrieving the data and trying display it on my table view the output is not complete. I have 3 tableviews, 1 is for the list of countries the 2nd is for the list of <subsidiary> the 3rd is for the information. The problem occurs when 1 country has 2 or more <subsidiary>, it only display the last subsidiary of that country. here is my xml
as you can see the <countryname> Denmark has two <subsidiary> in it. can you help me display all the subsidiary in that country?
here is my parser class, DON'T MIND THE app.infoarray,
Code:
<?xml version="1.0" encoding="UTF-8"?>
<countries>
<country>
<countryname>Philippines</countryname>
<subsidiaries>
<subsidiary>
<name id = "1">Sartorius Philippines Inc.</name>
<address>Unit 20-A The World Centre Building, 330 Senator Gil Puyat Avenue Makati 1209 City Philippines, Philippines</address>
<phone>+63.2.8640.929</phone>
<fax>+63.28640.932</fax>
<email>enquiry.philippines@sartorius.com</email>
<website>http://www.sartorius-mechatronics.com.ph</website>
</subsidiary>
</subsidiaries>
</country>
<country>
<countryname>Denmark</countryname>
<subsidiaries>
<subsidiary>
<name>Sartorius Stedim Nordic A|S</name>
<address>stedim 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>Sartorius 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>
</subsidiaries>
</country>
</countries>
as you can see the <countryname> Denmark has two <subsidiary> in it. can you help me display all the subsidiary in that country?
here is my parser class, DON'T MIND THE app.infoarray,
Code:
#import "Parser.h"
@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];
app.infoarray = [[NSMutableArray alloc]init];
}
if ([elementName isEqualToString:@"country"])
{
theList = [[List alloc]init];
temp = [[NSMutableString alloc]init];
}
if ([elementName isEqualToString:@"subsidiary"]) {
theList.countryname = temp;
[app.infoarray addObject:theList.countryname];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"subsidiary"])
{
[app.listArray addObject:theList];
}
else
{
if ([elementName isEqualToString:@"countryname"])
{
temp = 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
Last edited by a moderator: