I have a table with trs that look like this.
<tr>
<td><a href="http://www.mysite.com">Link</a></td>
<td>value 2</td>
<td>value 3</td>
<td>value 4</td>
<td>value 5</td>
</tr>
I’m using xPath to select all <tr> and looping through them.
foreach($xpathResult as $item){
//print the href of the first td
//print the nodeValue of the second td
//print the nodeValue of the 3rd td
//print the nodeValue of the 4th td
//print the nodeValue of the 5th td
}
How do I print the href of the first td and the nodeValue of each td thereafter? There’s firstChild and lastChild, but how do I get to the middle s? I could use firstChild->nextSibling and firstChild->nextSibling->nextSibling but isn’t there an easier way?
Just use a loop on
childNodes, like so: