chregu          Sat Apr  5 14:56:42 2003 EDT

  Modified files:              
    /php4/ext/domxml    php_domxml.c php_domxml.h 
  Log:
  @- Added domxml_doc_create_document_fragment() and 
  @    domxml_document_fragment_open_mem(string) method (Christian)
  Useful for adding and parsing (well-balanced) document fragments.
  - Bumped up API version number
  
  
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.243 php4/ext/domxml/php_domxml.c:1.244
--- php4/ext/domxml/php_domxml.c:1.243  Thu Apr  3 05:21:19 2003
+++ php4/ext/domxml/php_domxml.c        Sat Apr  5 14:56:41 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_domxml.c,v 1.243 2003/04/03 10:21:19 chregu Exp $ */
+/* $Id: php_domxml.c,v 1.244 2003/04/05 19:56:41 chregu Exp $ */
 
 /* TODO
  * - Support Notation Nodes
@@ -152,6 +152,7 @@
 static int le_domxmlcdatap;
 static int le_domxmltextp;
 static int le_domxmlpip;
+static int le_domxmldocumentfragmentp;
 static int le_domxmlcommentp;
 static int le_domxmlnotationp;
 static int le_domxmlparserp;
@@ -182,6 +183,7 @@
 zend_class_entry *domxmlcdata_class_entry;
 zend_class_entry *domxmltext_class_entry;
 zend_class_entry *domxmlpi_class_entry;
+zend_class_entry *domxmldocumentfragment_class_entry;
 zend_class_entry *domxmlcomment_class_entry;
 zend_class_entry *domxmlnotation_class_entry;
 zend_class_entry *domxmlentity_class_entry;
@@ -312,6 +314,7 @@
        PHP_FALIAS(create_cdata_section,        domxml_doc_create_cdata_section,       
 NULL)
        PHP_FALIAS(create_entity_reference,     domxml_doc_create_entity_reference,    
 NULL)
        PHP_FALIAS(create_processing_instruction,       
domxml_doc_create_processing_instruction,       NULL)
+       PHP_FALIAS(create_document_fragment,    domxml_doc_create_document_fragment,   
 NULL)
        PHP_FALIAS(get_elements_by_tagname,     domxml_doc_get_elements_by_tagname,    
 NULL)
        PHP_FALIAS(get_element_by_id,           domxml_doc_get_element_by_id,   NULL)
        /* Everything below this comment is none DOM compliant */
@@ -480,6 +483,11 @@
        {NULL, NULL, NULL}
 };
 
+static zend_function_entry php_domxmldocumentfragment_class_functions[] = {
+               PHP_FALIAS(open_mem,                                    
domxml_document_fragment_open_mem,                              NULL)
+               {NULL, NULL, NULL}
+};
+
 #if defined(LIBXML_XPATH_ENABLED)
 static zend_function_entry php_xpathctx_class_functions[] = {
        PHP_FALIAS(xpath_eval,                          xpath_eval,                    
                         NULL)
@@ -1241,6 +1249,17 @@
                        break;
                }
 
+               case XML_DOCUMENT_FRAG_NODE:
+               {
+                       xmlNodePtr nodep = obj;
+                       if(!wrapper_in)
+                               object_init_ex(wrapper, 
domxmldocumentfragment_class_entry);
+                       add_property_stringl(wrapper, "name", "#document-fragment", 
18, 1);
+                       rsrc_type = le_domxmldocumentfragmentp;
+                       add_property_long(wrapper, "type", Z_TYPE_P(nodep));
+                       break;
+               }
+               
                /* FIXME: nodes of type XML_DTD_NODE used to be domxmldtd_class_entry.
                 * but the DOM Standard doesn't have a DomDtd class. The DocumentType
                 * class seems to be want we need and the libxml dtd functions are
@@ -1461,7 +1480,7 @@
        }
 
        xmlFreeParserCtxt(ctxt);
-    
+
        return(ret);
 }
 
@@ -1485,6 +1504,7 @@
        le_domxmlcdatap = zend_register_list_destructors_ex(php_free_xml_node, NULL, 
"domcdata", module_number);
        le_domxmlentityrefp = zend_register_list_destructors_ex(php_free_xml_node, 
NULL, "domentityref", module_number);
        le_domxmlpip = zend_register_list_destructors_ex(php_free_xml_node, NULL, 
"dompi", module_number);
+       le_domxmldocumentfragmentp = 
zend_register_list_destructors_ex(php_free_xml_node, NULL, "domdocumentfragment", 
module_number);
        le_domxmlparserp =      zend_register_list_destructors_ex(php_free_xml_parser, 
NULL, "domparser", module_number);
        le_domxmldoctypep = zend_register_list_destructors_ex(php_free_xml_node, NULL, 
"domdocumenttype", module_number);
        le_domxmldocp = zend_register_list_destructors_ex(php_free_xml_doc, NULL, 
"domdocument", module_number);
@@ -1539,6 +1559,9 @@
        INIT_OVERLOADED_CLASS_ENTRY(ce, "domprocessinginstruction", 
php_domxmlpi_class_functions, NULL, NULL, NULL);
        domxmlpi_class_entry = zend_register_internal_class_ex(&ce, 
domxmlnode_class_entry, NULL TSRMLS_CC);
 
+       INIT_OVERLOADED_CLASS_ENTRY(ce, "domdocumentfragment", 
php_domxmldocumentfragment_class_functions, NULL, NULL, NULL);
+       domxmldocumentfragment_class_entry = zend_register_internal_class_ex(&ce, 
domxmlnode_class_entry, NULL TSRMLS_CC);
+
        INIT_OVERLOADED_CLASS_ENTRY(ce, "domnotation", 
php_domxmlnotation_class_functions, NULL, NULL, NULL);
        domxmlnotation_class_entry = zend_register_internal_class_ex(&ce, 
domxmlnode_class_entry, NULL TSRMLS_CC);
 
@@ -2360,15 +2383,21 @@
                }
        }
        /* end libxml2 code */
-       
-       if (NULL == new_child) {
+       if (child->type == XML_DOCUMENT_FRAG_NODE) {
+               new_child = xmlAddChildList(parent, child->children);
+               if (NULL != new_child) {
+                       /* the children are copied, not moved, but domstandard wants 
to move it 
+                          therefore we delete the reference here */
+                       child->children = NULL;
+               }
+       } else if (NULL == new_child) {
                new_child = xmlAddChild(parent, child);
        }
 
        if (NULL == new_child) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't append node");
                RETURN_FALSE;
-       }
+       } 
 
        DOMXML_RET_OBJ(rv, new_child, &ret);
 }
@@ -2460,13 +2489,27 @@
                        new_child = xmlAddPrevSibling(refp, child);
                }
        } else {
-               /* first unlink node, if child is already a child of parent
-                       for some strange reason, this is needed
-                */
-               if (child->parent == parent){
-                       xmlUnlinkNode(child);
+               
+               if (child->type == XML_DOCUMENT_FRAG_NODE) {
+                       new_child = xmlAddChildList(parent, child->children);
+                       if (NULL != new_child) {
+                       /* the children are copied, not moved, but domstandard wants 
to move it 
+                          therefore we delete the reference here */
+                               
+                          child->children = NULL;
+                       }
+               } else {
+               
+                       /* first unlink node, if child is already a child of parent
+                               for some strange reason, this is needed
+                        */
+               
+                       if (child->parent == parent){
+                               xmlUnlinkNode(child);
+                       }
+               
+                       new_child = xmlAddChild(parent, child);
                }
-               new_child = xmlAddChild(parent, child);
        }
                
 
@@ -3611,6 +3654,54 @@
        }
 }
 /* }}} */
+
+/* {{{ proto object domxml_doc_create_document_fragement()
+   Creates new document fragement node */
+PHP_FUNCTION(domxml_doc_create_document_fragment)
+{
+       zval *id, *rv = NULL;
+       xmlNode *node;
+       xmlDocPtr docp = NULL;
+       int ret;
+
+       DOMXML_PARAM_NONE(docp, id, le_domxmldocumentfragmentp);
+       
+
+       node = xmlNewDocFragment (docp);
+       if (!node) {
+               RETURN_FALSE;
+       }
+       DOMXML_RET_OBJ(rv, node, &ret); 
+}
+/* }}} */
+
+/* {{{ proto bool domxml_document_framgent_open_mem(string buf)
+   Parses a string with a well-balanced XML-Fragment and appends it to the 
document-fragment */
+PHP_FUNCTION(domxml_document_fragment_open_mem)
+{
+       zval *id;
+       xmlNodePtr dfp = NULL, last = NULL;     
+       char *buf;
+       int ret, buf_len;
+       xmlNodePtr lst;
+       
+       DOMXML_PARAM_TWO(dfp, id, le_domxmldocumentfragmentp,"s",&buf, &buf_len);
+
+       ret = xmlParseBalancedChunkMemory(dfp->doc, NULL, NULL, 0, (xmlChar *) buf, 
&lst);
+       if (ret != 0) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input string is 
not balanced (well-formed)");   
+                       RETURN_FALSE;
+       }
+       
+       last = xmlAddChildList(dfp, lst);
+       
+       if (last == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add 
child list");   
+                       RETURN_FALSE;
+       }
+       
+       RETURN_TRUE;
+}
 
 /* {{{ proto object domxml_doc_imported_node(object node, bool recursive)
    Creates new element node */
Index: php4/ext/domxml/php_domxml.h
diff -u php4/ext/domxml/php_domxml.h:1.76 php4/ext/domxml/php_domxml.h:1.77
--- php4/ext/domxml/php_domxml.h:1.76   Thu Apr  3 05:21:19 2003
+++ php4/ext/domxml/php_domxml.h        Sat Apr  5 14:56:41 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_domxml.h,v 1.76 2003/04/03 10:21:19 chregu Exp $ */
+/* $Id: php_domxml.h,v 1.77 2003/04/05 19:56:41 chregu Exp $ */
 
 #ifndef PHP_DOMXML_H
 #define PHP_DOMXML_H
@@ -53,7 +53,7 @@
     therefore it's easier for the script-programmers to check, what's working how
    Can be checked with phpversion("domxml");
 */
-#define DOMXML_API_VERSION "20020814"
+#define DOMXML_API_VERSION "20030405"
 
 extern zend_module_entry domxml_module_entry;
 #define domxml_module_ptr &domxml_module_entry
@@ -94,6 +94,7 @@
 PHP_FUNCTION(domxml_doc_create_text_node);
 PHP_FUNCTION(domxml_doc_create_comment);
 PHP_FUNCTION(domxml_doc_create_processing_instruction);
+PHP_FUNCTION(domxml_doc_create_document_fragment);
 PHP_FUNCTION(domxml_doc_create_attribute);
 PHP_FUNCTION(domxml_doc_create_cdata_section);
 PHP_FUNCTION(domxml_doc_create_entity_reference);
@@ -185,9 +186,12 @@
 PHP_FUNCTION(domxml_entity_system_id);
 PHP_FUNCTION(domxml_entity_notation_name);
 
-/* Class ProcessingInstructions */
+/* Class ProcessingInstructions methods*/
 PHP_FUNCTION(domxml_pi_target);
 PHP_FUNCTION(domxml_pi_data);
+
+/* Class DocumentFragment methods */
+PHP_FUNCTION(domxml_document_fragment_open_mem);
 
 /* Class Parser methods */
 PHP_FUNCTION(domxml_parser);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to