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
128a129 > PHP_FUNCTION(dom_document_output);
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 */ >
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php