I am trying to parse xml file and get no errors but when trying to read it, parser:didStartElement event is not triggered. What I am doing wrong? Thanks for help.
- (void)viewDidLoad
{
[super viewDidLoad];
// xml connect
NSURL *url = [[NSURL alloc] initWithString:@"http://www.test.com/list.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error!");
}
// reading xml...
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"main"]) {
//Initialize the array.
apps = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"prog"]) {
//Extract the attribute here.
idUsuari = [attributeDict objectForKey:@"Id"];
NSLog(@"ID: %@", idUser);
}
}
You haven’t set your view controller as the XML Parser’s delegate:
After you alloc / init. Without this the parser does not know who to send the delegate messages to.