Finding number of nodes in PHP, DOM, XPath

I am loading HTML into DOM and then querying it using XPath in PHP. My current problem is how do I find out how many matches have been made, and once that is ascertained, how do I access them?

I currently have this dirty solution:

$i = 0;  
foreach($nodes as $node) {  
    echo $dom->savexml($nodes->item($i));  
    $i++;
}

Is there a cleaner solution to find the number of nodes, I have tried count(), but that does not work.

Finding number of nodes in PHP, DOM, XPath