DOMDocument Extension: Output current node list

From: Date: Tue, 29 Jul 2008 22:34:01 +0000
Subject: DOMDocument Extension: Output current node list
Groups: php.internals 
Request: Send a blank email to internals+get-39445@lists.php.net to get a copy of this message
Hello, this is my first posting and first patch proposal, so please be kind. :) (This message might occur more then once, i dont seem to get friends with the list server) I recognized at work today that DOMDocument has two function saveHTML and saveHTMLFile, but only a save function for the "unfiltered" xml node structure to save to a file although libxml provides the functionality to export the data to string. This is bad because saveHTML(File) does lots of filtering on the output and if the document still has internal placeholders inside because its not finished they won't be recognized again. save() circumvents this by just printing the original inputted data, but needs to be used by saving the data into a tmp file and extracting it back by using file_get_contents for example. I created a patch that adds a new method "DOMDocument::ouput" that does what save() does just returns the output as a string from the function. I have attached the two diffs, they go in "ext/dom/" I tested this with 5.2.6. They are essentially copy paste and merge of the DOMDocument::save and DOMDocument::saveHtml functions. I changed the PHP.net manual snippet as a demo: <?php $doc = new DOMDocument('1.0'); $root = $doc->createElement('html'); $root = $doc->appendChild($root); $head = $doc->createElement('head'); $head = $root->appendChild($head); $title = $doc->createElement('title'); $title = $head->appendChild($title); $text = $doc->createTextNode('This is the title'); $text = $title->appendChild($text); echo $doc->output(); ?> -- Benjamin Eberlei http://www.beberlei.de

Attachment: [text/x-diff] dom_fe.h.diff
Attachment: [text/x-diff] document.diff
« previous php.internals (#39445) next »