rrichards Wed Jan 7 10:33:26 2004 EDT Modified files: /php-src/ext/dom document.c /php-src/ext/dom/tests dom_xinclude.phpt Log: Fix bug #26815 (foreach (DOM) childnodes causes error using Xinclude) update xinclude test Index: php-src/ext/dom/document.c diff -u php-src/ext/dom/document.c:1.41 php-src/ext/dom/document.c:1.42 --- php-src/ext/dom/document.c:1.41 Sun Dec 21 13:22:14 2003 +++ php-src/ext/dom/document.c Wed Jan 7 10:33:24 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: document.c,v 1.41 2003/12/21 18:22:14 iliaa Exp $ */ +/* $Id: document.c,v 1.42 2004/01/07 15:33:24 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -1441,19 +1441,65 @@ } /* }}} end dom_document_savexml */ +static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur TSRMLS_DC) { + xmlNodePtr xincnode; + + xincnode = cur; + cur = cur->next; + xmlUnlinkNode(xincnode); + php_libxml_node_free_resource(xincnode TSRMLS_CC); + + return cur; +} + +static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) { + while(cur) { + if (cur->type == XML_XINCLUDE_START) { + cur = php_dom_free_xinclude_node(cur TSRMLS_CC); + + /* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */ + while(cur && cur->type != XML_XINCLUDE_END) { + cur = cur->next; + } + + if (cur && cur->type == XML_XINCLUDE_END) { + cur = php_dom_free_xinclude_node(cur TSRMLS_CC); + } + } else { + if (cur->type == XML_ELEMENT_NODE) { + php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC); + } + cur = cur->next; + } + } +} + /* {{{ proto int dom_document_xinclude() Substitutues xincludes in a DomDocument */ PHP_FUNCTION(dom_document_xinclude) { zval *id; xmlDoc *docp; + xmlNodePtr root; int err; dom_object *intern; DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern); err = xmlXIncludeProcess (docp); - + + /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these + are added via xmlXIncludeProcess to mark beginning and ending of xincluded document + but are not wanted in resulting document - must be done even if err as it could fail after + having processed some xincludes */ + root = (xmlNodePtr) docp->children; + while(root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) { + root = root->next; + } + if (root) { + php_dom_remove_xinclude_nodes(root TSRMLS_CC); + } + if (err) { RETVAL_LONG(err); } else { Index: php-src/ext/dom/tests/dom_xinclude.phpt diff -u php-src/ext/dom/tests/dom_xinclude.phpt:1.2 php-src/ext/dom/tests/dom_xinclude.phpt:1.3 --- php-src/ext/dom/tests/dom_xinclude.phpt:1.2 Fri Oct 31 11:12:27 2003 +++ php-src/ext/dom/tests/dom_xinclude.phpt Wed Jan 7 10:33:25 2004 @@ -10,7 +10,10 @@ $dom = new domdocument; $dom->load(dirname(__FILE__)."/xinclude.xml"); $dom->xinclude(); -print $dom->saveXML(); +print $dom->saveXML()."\n"; +foreach ($dom->documentElement->childNodes as $node) { + print $node->nodeName."\n"; +} --EXPECT-- <?xml version="1.0"?> @@ -23,3 +26,8 @@ <author>John Steinbeck</author> </book> </foo> + +#text +book +book +#text
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php