2

In the code below:

<tbody>
  <tr class='even'>
    <th>header 1</th>
    <td>11</td>
    <td>12</td>
  </tr>
  <tr class='even'>
    <th>header 2</th>
    <td>21</td>
    <td>22</td>
  </tr>
</tbody>

When I run, $xpath->query("//tr[@class='even']")

It only shows me the contents of the <th> tags. Shouldn't I be getting the contents of the <td> as well i.e. everything inside the <tr> tags?

If not how can I get the td without having to write separate ones like this:

$xpath->query("//tr[@class='even']/th")
$xpath->query("//tr[@class='even']/td")
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
fractal5
  • 2,034
  • 4
  • 29
  • 50

1 Answers1

1

You can use * selector that select any tag.

$xpath->query("//tr[@class='even']/*")

The above code select every child of tr.even. Also you can use | (OR) operator like bottom code.

$xpath->query("//tr[@class='even']/td | //tr[@class='even']/th");
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Mohammad
  • 21,175
  • 15
  • 55
  • 84