Relative DOMNode xpath query in PHP

I use something like //*[@attr] to search for nodes with a given attribute. If i give a reference node to $xpath->query, it does a non-relative search.


Remove the // to search for children of the context node.

$xpath->query('*[@attr]', $parentNode);

Get all child nodes

But then that doesn't get all descendants... So something like:

$xpath->query('descendant::*[@attr]', $parentNode);

where you would change the *[@attr] portion to match whatever you're looking for.