我正在使用可可,我想解析一个xml文件。
但也有2个警告,在我的代码在这里
使用NSData解析xml
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,它不工作
如果(成功){ 的NSLog(@ “没有错误”); // - 用户数:%I”,[解析[用户数]); // 拿到这里用户 的NSMutableArray *用户的阵列= [解析用户]; //我如何解析此解析器是XML解析器不是一个NSXML分析器?? – user1503496 2012-07-09 14:17:52