Reputation: 317
I was tried to parse html data using TFHpple
as mentioned below
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];
NSString *tutorialsXpathQueryString = @"//body";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
After done with above step I am getting tutorialsNodes array which contain all data.
I want to find each tag in it with its content.
I need tag to identified is it image or text etc.
I don't understand how to get it.
Upvotes: 0
Views: 229
Reputation: 3231
Something like this, perhaps?
...
for (TFHppleElement *element in tutorialsNodes)
{
[self handleElement:element];
}
...
}
- (void)handleElement:(TFHppleElement *)element
{
for (TFHppleElement *child in element.children)
{
NSString *textInsideTheChildElement = child.content;
if ([child.tagName isEqualToString:@"img"])
{
NSString *sourceUrl = child.attributes["src"];
}
else
{
[self handleElement:child];
}
}
}
Upvotes: 1