Posted By

titosemi on 12/11/10


Tagged

debug dump XPath


Versions (?)

titosemi


 / Published in: PHP
 

  1. public function dom_dump($obj) {
  2. if ($classname = get_class($obj)) {
  3. $retval = "Instance of $classname, node list: \n";
  4. switch (true) {
  5. case ($obj instanceof DOMDocument):
  6. $retval .= "XPath: {$obj->getNodePath()}\n".$obj->saveXML($obj);
  7. break;
  8. case ($obj instanceof DOMElement):
  9. $retval .= "XPath: {$obj->getNodePath()}\n".$obj->ownerDocument->saveXML($obj);
  10. break;
  11. case ($obj instanceof DOMAttr):
  12. $retval .= "XPath: {$obj->getNodePath()}\n".$obj->ownerDocument->saveXML($obj);
  13. break;
  14. case ($obj instanceof DOMNodeList):
  15. for ($i = 0; $i < $obj->length; $i++) {
  16. $retval .= "Item #$i, XPath: {$obj->item($i)->getNodePath()}\n".
  17. "{$obj->item($i)->ownerDocument->saveXML($obj->item($i))}\n";
  18. }
  19. break;
  20. default:
  21. return "Instance of unknown class";
  22. }
  23. } else {
  24. return 'no elements...';
  25. }
  26. return $retval;
  27. }

Report this snippet  

You need to login to post a comment.