protected function getNodeDepth(DomNode $node) { $depth = -2; while ($node) { ++$depth; $node = $node->parentNode; } return $depth; }