我正在使用可可,我想解析一个 xml 文件。
但是我的代码中有 2 个警告
incompatible Objective-C types 'struct NSString *', expected 'struct NSURL *' when passing argument 1 of 'initWithContentsOfURL:' from distinct Objective-C type
和class 'XMLParser' does not implement the 'NSXMLParserDelegate' protocol
这是我的代码:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *data = [[NSData alloc] initWithContentsOfURL:@"/Users.xml"]; // here is the first warning
// create and init NSXMLParser object
NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithData:data];
// create and init our delegate
XMLParser *parser = [[XMLParser alloc] initXMLParser];
// set delegate
[nsXmlParser setDelegate:parser]; // here is the second warning
// parsing...
BOOL success = [nsXmlParser parse];
// test the result
if (success) {
NSLog(@"No errors");// - user count : %i", [parser [users count]]);
// get array of users here
// NSMutableArray *users = [parser users];
} else {
NSLog(@"Error parsing document!");
}
[parser release];
[nsXmlParser release];
[pool drain];
return NSApplicationMain(argc, (const char **) argv);
}
请问我该如何解决?当我运行时,它告诉我程序收到信号 SIGABRT 并且它不起作用