At the last part of the tutorial I am having an issue with the users variable, its saying users variable is undeclared.
It is being declared in my NSXMLPaser class that I created as a NSMutableArray and I am “#import”ing the header file of NSXMLPaser class…
Here is the link to the tutorial I am working through, any help would be greatly appreciated.
http://wiki.cs.unh.edu/wiki/index.php/Parsing_XML_data_with_NSXMLParser
- (void) doParse:(NSData *)data {
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"xml"];
NSData * fileData = [NSData dataWithContentsOfFile:filePath];
// create and init NSXMLParser object
NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithData:fileData];
// create and init our delegate
XMLParser *parser = [[XMLParser alloc] initXMLParser];
// set delegate
[nsXmlParser setDelegate:parser];
// parsing...
BOOL success = [nsXmlParser parse];
// test the result
if (success) {
NSLog(@"No errors - user count : %i", [parser [users count]]); // users undeclared error here
// get array of users here
// NSMutableArray *users = [parser users];
} else {
NSLog(@"Error parsing document!");
}
[parser release];
[nsXmlParser release];
}
Either you use “[parser.users count]” like Babji said or you could use the dot notation for everything, like “parser.users.count”.
Also, you could use “[[parser users] count]”. This means you first get the collection users of the parser (“[parser users]”) and then you call count on that collection (“[[parser users] count]”).