0

我有这个文件:

XMLParser.h

#import <Foundation/Foundation.h>

 @interface XMLParser : NSObject <NSXMLParserDelegate>
{

    NSXMLParser *parser;

}

-(id)initWitData:(NSData *)data;
-(void)parseXML;


@end

XMLParser.m(它的一部分)

 #import "XMLParser.h"
 @implementation XMLParser

- (id)initWitData:(NSData *)data
 {
    if (self = [super init]) {

    parser = [[NSXMLParser alloc] initWithData:data];

    [parser setDelegate:self];
}
return self;
}


 - (void)parseXML{

[parser parse];

 };

视图控制器.h

#import <UIKit/UIKit.h>
#import "XMLParser.h"

@interface ViewController : UIViewController <CLLocationManagerDelegate>
{

   NSXMLParser *xmlToString;
}


@end

和 ViewController.m

 #import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:@"world" ofType:@"xml"];

NSData *data = [[NSData alloc]initWithContentsOfFile:xmlFilePath];
xmlToString = [[NSXMLParser alloc]initWithData:data];
//[xmlToString setDelegate:self];
[xmlToString setShouldResolveExternalEntities:YES];
[xmlToString parseXML]; // I am getting the error here.

}

有谁能够帮我?我在其他项目及其工作中做了几乎相同的事情!!!唯一的区别是 initWithData

4

1 回答 1

2

您正在创建一个NSXMLParser然后尝试从中调用一个方法XMLParser。你确定你不是要声明xmlToStringXMLParser*然后说

xmlToString = [[XMLParser alloc] initWithData:data];

当然,您的调用-setShouldResolveExternalEntities:将失败,因此您可能需要公开您的底层NSXMLParser对象。

于 2013-02-14T00:40:23.107 回答