title: Need help with PHP DOM XPath parsing table
body: <p>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.</p>
  
  <p>The page contains a table with dates and X number of events for the date.</p>
  
  <p>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.</p>
  
  <p>This is what the HTML on the page looks like:</p>
  
  <blockquote>
  <pre><code>&lt;table&gt;
      &lt;tr valign="bottom"&gt;
          &lt;td colspan="4"&gt;2009-02-26&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="top"&gt;
          &lt;td&gt;21:00&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="top"&gt;
          &lt;td&gt;23:00&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="bottom"&gt;
          &lt;td colspan="4"&gt;2009-02-27&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="top"&gt;
          &lt;td&gt;06:00&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="top"&gt;
          &lt;td&gt;10:00&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="top"&gt;
          &lt;td&gt;13:00&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
          &lt;td&gt;Column data&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  </blockquote>
  
  <p>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.</p>
  
  <p>The xpath query I use to get the date trs is</p>
  
  <pre><code>$result = $xpath-&gt;query('//tr[@valign="bottom"][position()&lt;3]);
  </code></pre>
  
  <p>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.</p>