Re: xml xinclude

From: Date: Thu, 09 Jan 2003 14:04:13 +0000
Subject: Re: xml xinclude
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-93286@lists.php.net to get a copy of this message
At 03:44 PM 1/8/2003 +0100, you wrote: >At 15:35 08.01.2003, Pawel wrote: >>Hello, >> >>libxml (tested with 2.4.30) creates these additional nodes when parsing >>documents with xincludes: XML_XINCLUDE_START and XML_XINCLUDE_END. >>PHP has no support for these nodes and chokes when it encounters them, >>therefore walking the xml tree after issuing $doc->xinclude() fails. >> >>The only work-around I could come up with is: >>$doc = domxml_open_mem($doc->dump_mem()) >>which gets rid of the XML_XINCLUDE_START and XML_XINCLUDE_END nodes >> >>The problem comes up when you have entities in the xincluded document, >>which don't get substituted. >>This short patch substitutes any entity references you might have in the >>xincluded document. > >Why not check for XML_XINCLUDE_START and XML_XINCLUDE_END or >the libxml version in configure and make the necessary changes to the .c >file? > >marcus Hello, Attached is my attempt at adding support for XML_XINCLUDE_START and XML_XINCLUDE_END to php. This removes the need for previously mentioned $doc = domxml_open_mem($doc->dump_mem()) xmlNodeGetContent() seems to return null for xincluded nodes with entity references (libxml bug ?), therefore I left my first patch which substitutes entity references in the xincluded document. Pawel

--- ext/domxml/php_domxml.c 2003-01-09 08:50:33.000000000 -0500 +++ ext/domxml/php_domxml.c.new 2003-01-09 08:50:27.000000000 -0500 @@ -1121,6 +1121,8 @@ switch (Z_TYPE_P(obj)) { + case XML_XINCLUDE_START: + case XML_XINCLUDE_END: case XML_ELEMENT_NODE: { xmlNodePtr nodep = obj; @@ -1585,6 +1587,8 @@ REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_DECL_NODE", XML_ATTRIBUTE_DECL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ENTITY_DECL_NODE", XML_ENTITY_DECL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_NAMESPACE_DECL_NODE", XML_NAMESPACE_DECL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_XINCLUDE_START", XML_XINCLUDE_START, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XML_XINCLUDE_END", XML_XINCLUDE_END, CONST_CS | CONST_PERSISTENT); #ifdef XML_GLOBAL_NAMESPACE REGISTER_LONG_CONSTANT("XML_GLOBAL_NAMESPACE", XML_GLOBAL_NAMESPACE, CONST_CS | CONST_PERSISTENT); #endif @@ -1889,6 +1893,14 @@ str = "#document-fragment"; break; + case XML_XINCLUDE_START: + str = "#xinclude-start"; + break; + + case XML_XINCLUDE_END: + str = "#xinclude-end"; + break; + default: str = NULL; break; @@ -4556,6 +4568,9 @@ zend_hash_update(Z_OBJPROP_P(value), "children", sizeof("children"), (void *) &children, sizeof(zval *), NULL); } */ add_property_string(pattr, "name", (char *) (attr->name), 1); + +/* fprintf(stderr, "setting attribute value to %s\n", xmlNodeGetContent( (xmlNodePtr) attr)); + NOTE: xmlNodeGetContent((xmlNodePtr) attr) returns a null for xincluded nodes with refrences */ add_property_string(pattr, "value", xmlNodeGetContent((xmlNodePtr) attr), 1); zend_hash_next_index_insert(Z_ARRVAL_PP(attributes), &pattr, sizeof(zval *), NULL); attr = attr->next; @@ -4953,12 +4968,15 @@ { zval *id; xmlDoc *docp; - int err; + int err; + int prevSubstValue; DOMXML_PARAM_NONE(docp, id, le_domxmldocp); + prevSubstValue = xmlSubstituteEntitiesDefault (1); err = xmlXIncludeProcess (docp); - + xmlSubstituteEntitiesDefault (prevSubstValue); + if (err) { RETVAL_LONG(err); } else {
« previous php.dev (#93286) next »