关于iphone 利用hpple解析html的问题?最近在用happe解析html中的图片。有个翻页操作,如果请求的html中没有
关于iphone 利用hpple解析html的问题
?最近在用happe解析html中的图片。有个翻页操作,如果请求的html中没有需要解析的标记的话会造成xmllib2的内存泄露。
?
这一个是happ的一个bug吧。
?
修改方法:
修改 XPathQuery.m 类中的
写道NSArray *PerformXPathQuery(xmlDocPtr doc, NSString *query)
{
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;
/* Create xpath evaluation context */
xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL)
{
NSLog(@"Unable to create XPath context.");
return nil;
}
/* Evaluate xpath expression */
xpathObj = xmlXPathEvalExpression((xmlChar *)[query cStringUsingEncoding:NSUTF8StringEncoding], xpathCtx);
if(xpathObj == NULL) {
NSLog(@"Unable to evaluate XPath.");
return nil;
}
xmlNodeSetPtr nodes = xpathObj->nodesetval;
if (!nodes)
{
NSLog(@"Nodes was nil.");
return nil;
}
NSMutableArray *resultNodes = [NSMutableArray array];
for (NSInteger i = 0; i < nodes->nodeNr; i++)
{
NSDictionary *nodeDictionary = DictionaryForNode(nodes->nodeTab[i], nil);
if (nodeDictionary)
{
[resultNodes addObject:nodeDictionary];
}
}
/* Cleanup */
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
return resultNodes;
}
?
?注意红色部分一个修改为如下:
写道if (!nodes)
{
NSLog(@"Nodes was nil.");
/* Cleanup */
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx); return nil;
}
?
?