views:

449

answers:

3

I'm trying to debug a large and complex DOMDocument object in php. Ideally it'd be nice if I could get DOMDocument to output in a array-like format.

DoMDocument:

$dom = new DOMDocument();
$dom->loadHTML("<html><body><p>Hello World</p></body></html>");
var_dump($dom); //or something equivalent

This outputs

DOMDocument Object ( ) 

whereas I'd like it to output

DOMDocument:
html
=>body
==>p
===>Hello World

Or something like that. Why is there no handy debug or output for this?!?

A: 

Though I haven't tried it myself, check out Zend_Dom, part of the Zend Framework. Documentation and examples for most of the Zend Framework components is really thorough.

jakemcgraw
A: 

I just used DOMDocument::save. It's lame that it has to write to a file, but whatever.

Ray
If you did that, you could just do saveHTML instead and have it go to a string.
Paolo Bergantino
+1  A: 

http://usphp.com/manual/en/function.dom-domdocument-savexml.php

$dom->formatOutput = true;
echo $dom->saveXML();
Phill Pafford