1

I am writing a task to import a XML. Debugging is a pain as both var_dump and print_r return seemingly empty objects for DOM objects like DOMElement and DOMNodeList list, looking so:

object(DOMElement)#330 (0) {}
object(DOMNodeList)#335 (0) {}

But they are not empty as I can read the values.

What debugging options have I instead?

hakre
  • 184,866
  • 48
  • 414
  • 792
k0pernikus
  • 50,568
  • 57
  • 198
  • 317
  • Upgrade to PHP 5.4 and you will get more information, what you describe is only the case with the older PHP 5.3 version. See also [Debug a DOMDocument Object in PHP](http://stackoverflow.com/questions/684227/debug-a-domdocument-object-in-php) and [PHP XML how to output nice format](http://stackoverflow.com/q/8615422/367456). – hakre May 13 '12 at 15:05

2 Answers2

2

For a DomDocument I var_dump using the xml output.

var_dump($dom->saveXML());

For a DOMElement, I use (as seen here):

var_dump($domElement->ownerDocument->saveXML($domElement));

But DOMNodeList, I have no idea. Maybe you have to attach/append it to a DomDocument, and then var_dump it.

And btw, not showing internals of a DomDocument is reported (here: Reflection).

j0k
  • 22,303
  • 28
  • 77
  • 86
1

Solution: i wrote own monitoring function 'dom_test'

    function dom_test($DOM) {
      echo '<h1>'.get_class($DOM).'</h1>';
      // easiest way to traverse:
      echo 'LENGTH: '. @$DOM->length ."\n"; // if NodeList
      echo 'TAG: '. @$DOM->tagName ."\n"; // if Element
      echo 'CHILDS: '. @$DOM->childNodes->length ."\n"; // etc.
    }

hope this could help you!

pathoc
  • 11
  • 2