I just recently read about the DOM module in PHP and now I'm trying to use it for parsing a HTML document. The page said that this was a much better solution than using preg but I'm having a hard time figuring out how to use it.
The page contains a table with dates and X number of events for the date.
First I need to get the text (a date) from a tr with valign="bottom" and then I need to get all the column values from all the tr with valign="top" who is below that tr. I need all the column values from each tr below the tr with the date up until the next tr with valign="bottom" (next date). The number of tr with column data is unknown, can be zero or a lot of them.
This is what the HTML on the page looks like:
<table> <tr valign="bottom"> <td colspan="4">2009-02-26</td> </tr> <tr valign="top"> <td>21:00</td> <td>Column data</td> <td>Column data</td> <td>Column data</td> </tr> <tr valign="top"> <td>23:00</td> <td>Column data</td> <td>Column data</td> <td>Column data</td> </tr> <tr valign="bottom"> <td colspan="4">2009-02-27</td> </tr> <tr valign="top"> <td>06:00</td> <td>Column data</td> <td>Column data</td> <td>Column data</td> </tr> <tr valign="top"> <td>10:00</td> <td>Column data</td> <td>Column data</td> <td>Column data</td> </tr> <tr valign="top"> <td>13:00</td> <td>Column data</td> <td>Column data</td> <td>Column data</td> </tr> </table>
So far I've been able to get the first two dates (I'm only interested in the first two) but I don't know how to go from here.
The xpath query I use to get the date trs is
$result = $xpath->query('//tr[@valign="bottom"][position()<3]);
Now I need a way to connect all the events for that day to the date, ie. select all the tds and all the column values up until the next date tr.