Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39445 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33384 invoked from network); 29 Jul 2008 22:34:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jul 2008 22:34:16 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 87.230.78.165 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 87.230.78.165 www.mysqlusers.de Linux 2.5 (sometimes 2.4) (4) Received: from [87.230.78.165] ([87.230.78.165:58783] helo=mysqlusers.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/C1-39544-7EA9F884 for ; Tue, 29 Jul 2008 18:34:16 -0400 Received: from Debian-exim by mysqlusers.de with spam-scanned (Exim 4.63) (envelope-from ) id 1KNxlj-0008JF-Kb for internals@lists.php.net; Wed, 30 Jul 2008 00:34:12 +0200 X-Spam-Checker-Version: SpamAssassin 3.1.7-deb (2006-10-05) on mysqlusers.de X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED,AWL autolearn=disabled version=3.1.7-deb Received: from koln-4d0b13b8.pool.mediaways.net ([77.11.19.184] helo=benny-pc.local) by mysqlusers.de with esmtpa (Exim 4.63) (envelope-from ) id 1KNxlj-0008Ij-DM for internals@lists.php.net; Wed, 30 Jul 2008 00:34:11 +0200 To: internals@lists.php.net Date: Wed, 30 Jul 2008 00:34:01 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_Zr5jIIWcCP2WelN" Message-ID: <200807300034.01240.kontakt@beberlei.de> Subject: DOMDocument Extension: Output current node list From: kontakt@beberlei.de (Benjamin Eberlei) --Boundary-00=_Zr5jIIWcCP2WelN Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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: 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 --Boundary-00=_Zr5jIIWcCP2WelN Content-Type: text/x-diff; charset="utf-8"; name="dom_fe.h.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dom_fe.h.diff" 128a129 > PHP_FUNCTION(dom_document_output); --Boundary-00=_Zr5jIIWcCP2WelN Content-Type: text/x-diff; charset="utf-8"; name="document.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="document.diff" 148a149,152 > ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_output, 0, 0, 0) > ZEND_END_ARG_INFO(); > > static 246a251 > PHP_FALIAS(output, dom_document_output, arginfo_dom_document_output) 1826a1832,1859 > /* {{{ proto string dom_document_save( void ) ; > return string representation of the dom > */ > PHP_FUNCTION(dom_document_output) > { > zval *id; > xmlDoc *docp; > dom_object *intern; > xmlChar *mem; > int size; > > if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) { > return; > } > > DOM_GET_OBJ(docp, id, xmlDocPtr, intern); > > xmlDocDumpMemory(docp, &mem, &size); > if (!size) { > if (mem) > xmlFree(mem); > RETURN_FALSE; > } > RETVAL_STRINGL(mem, size, 1); > xmlFree(mem); > } > /* }}} end dom_document_output */ > --Boundary-00=_Zr5jIIWcCP2WelN--