hpple elements within elements

832 Views Asked by At

I have been using Hpple to parse some html in my iphone application (iOS5.1). I have searched for all 'td' elements within a table row. I am iterating through each of these elements, and for the most part I can retrieve all the information I need from the element, e.g.

[element objectForKey:@"rowspan"];

But one of the values I need is within the td:

<tr>
<td rowspan="3">  //This is my element
   <div>
      <a>link text</a>  //The link text is what I want
   </div>
</td>
</tr>

Is there a way of getting the 'a' tags within my element, I have tried the following, but it doesn't work:

[[[element firstChild] firstChild] content];

Any help would be greatly appreciated!

1

There are 1 best solutions below

0
On

I figured it out... The Xcode debugger wasn't as helpful compared to some other IDEs I work with, but once I found the 'print description' option I was able to see what was going on...

I was getting an error 'Invalid CFStringRef' when I tried [element content] and when I tried [[element firstChild] content] it printed "\n" which was not what I was expecting. Anyway, this is probably a really long way to get what I wanted, but this was my solution...

NSArray* childrenArray = [element children];
TFHppleElement *childElement = [childrenArray objectAtIndex:1];
TFHppleElement *newChildElement = [[childElement children] objectAtIndex:1];
NSString *name = [[newChildElement firstChild] content];  //This is the content I wanted