I'm using TFHpple (which uses XPath) to parse an HTML document. I can get the content of various nodes, etc. But the code I found on GitHub seems incomplete. It has a method to get the attributes of a node but the child array. So I wrote one and failed. The two "attributes" methods below work fine. Basically, I'd like to get the child array as a new node. I think I'm failing at the NSDictionary level. I tried to make a new TFHppleElement out of what I return in "children" below but... FAIL! Any clues?
This is from TFHppleElement.m:
- (NSDictionary *) attributesForNode: (NSDictionary *) myNode
{
NSMutableDictionary *translatedAttributes = [NSMutableDictionary dictionary];
for (NSDictionary *attributeDict in [myNode objectForKey: TFHppleNodeAttributeArrayKey])
{
//NSLog(@"attributeDict: %@", attributeDict);
[translatedAttributes setObject: [attributeDict objectForKey: TFHppleNodeContentKey]
forKey: [attributeDict objectForKey: TFHppleNodeAttributeNameKey]];
}
return translatedAttributes;
}
- (NSDictionary *) attributes
{
return [self attributesForNode: node];
}
- (BOOL) hasChildren
{
return [node objectForKey: TFHppleNodeChildArrayKey] != nil;
}
- (NSDictionary *) children
{
NSMutableDictionary *translatedChildren = [NSMutableDictionary dictionary];
for (NSDictionary *childDict in [node objectForKey: TFHppleNodeChildArrayKey])
{
[translatedChildren setObject: childDict
forKey: [childDict objectForKey: TFHppleNodeNameKey]];
}
return [node objectForKey: TFHppleNodeChildArrayKey];
}