Reputation: 4065
I have this files:
XMLParser.h
#import <Foundation/Foundation.h>
@interface XMLParser : NSObject <NSXMLParserDelegate>
{
NSXMLParser *parser;
}
-(id)initWitData:(NSData *)data;
-(void)parseXML;
@end
XMLParser.m (part of it)
#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];
};
ViewController.h
#import <UIKit/UIKit.h>
#import "XMLParser.h"
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
NSXMLParser *xmlToString;
}
@end
and the 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.
}
Can anybody help me? I have done almost the same in other project and its working!!! The only difference is the initWithData
Upvotes: 0
Views: 380
Reputation: 185711
You're creating an NSXMLParser
and then trying to call a method from XMLParser
on it. Are you sure you didn't mean to declare xmlToString
as an XMLParser*
and then say
xmlToString = [[XMLParser alloc] initWithData:data];
Of course, your call to -setShouldResolveExternalEntities:
will then fail, so you may need to expose your underlying NSXMLParser
object.
Upvotes: 2