ios - Grabbing the first child of a <tr> tag? -


currently i'm following ray wenderlich's tutorial dealing parsing html on ios. explained , according tree:

enter image description here

they extract title , url tag each tutorial.

this how create array hold tutorial object:

nsmutablearray *newtutorials = [[nsmutablearray alloc] initwithcapacity:0];     (tfhppleelement *element in tutorialsnodes) {         // 5         tutorial *tutorial = [[tutorial alloc] init];         [newtutorials addobject:tutorial];          // 6         tutorial.title = [[element firstchild] content];          // 7         tutorial.url = [element objectforkey:@"href"];     } 

now here question. i'm trying out on site. problem don't know how 4th child of every <tr> tag.

here html tree.

enter image description here

i'm trying fourth child every tag. don't know how approach it.

would correct?

        // 6         tutorial.title = [[element firstchild] content];          // 7         tutorial.amount = [[element fourthchild] objectforkey:@"td"]; 

you can use children property :)

first need reach out required tag in element children. can set xpath query one: div[@id='main']/table[@class='bodytext']/tbody/tr

then can fourth child using children property. here sample code.

//3 nsstring *tutorialsxpathquerystring = @"//div[@id='main']/table[@class='bodytext']/tbody/tr"; nsarray *tutorialsnodes = [tutorialsparser searchwithxpathquery:tutorialsxpathquerystring];  // 4 nsmutablearray *newtutorials = [[nsmutablearray alloc] initwithcapacity:0]; (tfhppleelement *element in tutorialsnodes) { // 5 tutorial *tutorial = [[tutorial alloc] init]; [newtutorials addobject:tutorial];  // 6 tfhppleelement *trtag = [[element children] objectatindex:3];  tutorial.title = [trtag content]; 

hope helps


Comments