这是我的项目类中召唤我的解析器的方法。这个方法是由我的viewController召唤的。
- (NSString*)img
{
if (img!=nil) return img;
if (_description!=nil)
{
// NSString* description = [NSString stringWithString:_description];
htmlParser = [[HtmlParser alloc] InitHtmlByString:_description];
}
return img;
}
这是我的解析器的初始化方法......
- (HtmlParser *) InitHtmlByString:(NSString *)htmlString {
NSString *description = currentHTMLElement.description;
NSLog(@"%@", description);
NSData *nsData = [[NSData alloc] initWithContentsOfFile:(NSString *)description];
elementArray = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithData:nsData];
parser.delegate = self;
[parser parse];
currentHTMLElement = [ArticleItem alloc];
return self;
}
现在我得到这样的输出:
013-02-11 15:26:18.564 DrillDownRSS[9251:c07](空)
2013-02-11 15:26:18.612 DrillDownRSS[9251:c07](空)
2013-02-11 15:26:18.662 DrillDownRSS[9251:c07](空)
2013-02-11 15:26:18.695 DrillDownRSS[9251:c07](空)
这是解决方案,感谢以下评论的周到建议。
// NSString *description = [NSString string];
NSData *nsData = [[NSData alloc] initWithContentsOfFile:(NSString *)string];
elementArray = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithData:nsData];
parser.delegate = self;
[parser parse];
NSLog(@"%@", string);
currentHTMLElement = [ArticleItem alloc];
return self;