Back to index

php5  5.3.10
document.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Christian Stocker <chregu@php.net>                          |
00016    |          Rob Richards <rrichards@php.net>                            |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: document.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "config.h"
00024 #endif
00025 
00026 #include "php.h"
00027 #if HAVE_LIBXML && HAVE_DOM
00028 #include "php_dom.h"
00029 #include <libxml/SAX.h>
00030 #ifdef LIBXML_SCHEMAS_ENABLED
00031 #include <libxml/relaxng.h>
00032 #include <libxml/xmlschemas.h>
00033 #endif
00034 
00035 typedef struct _idsIterator idsIterator;
00036 struct _idsIterator {
00037        xmlChar *elementId;
00038        xmlNode *element;
00039 };
00040 
00041 #define DOM_LOAD_STRING 0
00042 #define DOM_LOAD_FILE 1
00043 
00044 /* {{{ arginfo */
00045 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element, 0, 0, 1)
00046        ZEND_ARG_INFO(0, tagName)
00047        ZEND_ARG_INFO(0, value)
00048 ZEND_END_ARG_INFO();
00049 
00050 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_document_fragment, 0, 0, 0)
00051 ZEND_END_ARG_INFO();
00052 
00053 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_text_node, 0, 0, 1)
00054        ZEND_ARG_INFO(0, data)
00055 ZEND_END_ARG_INFO();
00056 
00057 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_comment, 0, 0, 1)
00058        ZEND_ARG_INFO(0, data)
00059 ZEND_END_ARG_INFO();
00060 
00061 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_cdatasection, 0, 0, 1)
00062        ZEND_ARG_INFO(0, data)
00063 ZEND_END_ARG_INFO();
00064 
00065 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_processing_instruction, 0, 0, 2)
00066        ZEND_ARG_INFO(0, target)
00067        ZEND_ARG_INFO(0, data)
00068 ZEND_END_ARG_INFO();
00069 
00070 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute, 0, 0, 1)
00071        ZEND_ARG_INFO(0, name)
00072 ZEND_END_ARG_INFO();
00073 
00074 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_entity_reference, 0, 0, 1)
00075        ZEND_ARG_INFO(0, name)
00076 ZEND_END_ARG_INFO();
00077 
00078 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name, 0, 0, 1)
00079        ZEND_ARG_INFO(0, tagName)
00080 ZEND_END_ARG_INFO();
00081 
00082 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_import_node, 0, 0, 2)
00083        ZEND_ARG_OBJ_INFO(0, importedNode, DOMNode, 0)
00084        ZEND_ARG_INFO(0, deep)
00085 ZEND_END_ARG_INFO();
00086 
00087 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_element_ns, 0, 0, 2)
00088        ZEND_ARG_INFO(0, namespaceURI)
00089        ZEND_ARG_INFO(0, qualifiedName)
00090        ZEND_ARG_INFO(0, value)
00091 ZEND_END_ARG_INFO();
00092 
00093 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_create_attribute_ns, 0, 0, 2)
00094        ZEND_ARG_INFO(0, namespaceURI)
00095        ZEND_ARG_INFO(0, qualifiedName)
00096 ZEND_END_ARG_INFO();
00097 
00098 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_elements_by_tag_name_ns, 0, 0, 2)
00099        ZEND_ARG_INFO(0, namespaceURI)
00100        ZEND_ARG_INFO(0, localName)
00101 ZEND_END_ARG_INFO();
00102 
00103 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_get_element_by_id, 0, 0, 1)
00104        ZEND_ARG_INFO(0, elementId)
00105 ZEND_END_ARG_INFO();
00106 
00107 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_adopt_node, 0, 0, 1)
00108        ZEND_ARG_OBJ_INFO(0, source, DOMNode, 0)
00109 ZEND_END_ARG_INFO();
00110 
00111 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_normalize_document, 0, 0, 0)
00112 ZEND_END_ARG_INFO();
00113 
00114 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_rename_node, 0, 0, 3)
00115        ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)
00116        ZEND_ARG_INFO(0, namespaceURI)
00117        ZEND_ARG_INFO(0, qualifiedName)
00118 ZEND_END_ARG_INFO();
00119 
00120 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_load, 0, 0, 1)
00121        ZEND_ARG_INFO(0, source)
00122        ZEND_ARG_INFO(0, options)
00123 ZEND_END_ARG_INFO();
00124 
00125 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_save, 0, 0, 1)
00126        ZEND_ARG_INFO(0, file)
00127 ZEND_END_ARG_INFO();
00128 
00129 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadxml, 0, 0, 1)
00130        ZEND_ARG_INFO(0, source)
00131        ZEND_ARG_INFO(0, options)
00132 ZEND_END_ARG_INFO();
00133 
00134 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savexml, 0, 0, 0)
00135        ZEND_ARG_OBJ_INFO(0, node, DOMNode, 1)
00136 ZEND_END_ARG_INFO();
00137 
00138 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_construct, 0, 0, 0)
00139        ZEND_ARG_INFO(0, version)
00140        ZEND_ARG_INFO(0, encoding)
00141 ZEND_END_ARG_INFO();
00142 
00143 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_validate, 0, 0, 0)
00144 ZEND_END_ARG_INFO();
00145 
00146 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_xinclude, 0, 0, 0)
00147        ZEND_ARG_INFO(0, options)
00148 ZEND_END_ARG_INFO();
00149 
00150 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1)
00151        ZEND_ARG_INFO(0, source)
00152 ZEND_END_ARG_INFO();
00153 
00154 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1)
00155        ZEND_ARG_INFO(0, source)
00156 ZEND_END_ARG_INFO();
00157 
00158 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
00159 ZEND_END_ARG_INFO();
00160 
00161 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtmlfile, 0, 0, 1)
00162        ZEND_ARG_INFO(0, file)
00163 ZEND_END_ARG_INFO();
00164 
00165 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_file, 0, 0, 1)
00166        ZEND_ARG_INFO(0, filename)
00167 ZEND_END_ARG_INFO();
00168 
00169 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_schema_validate_xml, 0, 0, 1)
00170        ZEND_ARG_INFO(0, source)
00171 ZEND_END_ARG_INFO();
00172 
00173 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_file, 0, 0, 1)
00174        ZEND_ARG_INFO(0, filename)
00175 ZEND_END_ARG_INFO();
00176 
00177 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_relaxNG_validate_xml, 0, 0, 1)
00178        ZEND_ARG_INFO(0, source)
00179 ZEND_END_ARG_INFO();
00180 
00181 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_registernodeclass, 0, 0, 2)
00182        ZEND_ARG_INFO(0, baseClass)
00183        ZEND_ARG_INFO(0, extendedClass)
00184 ZEND_END_ARG_INFO();
00185 /* }}} */
00186 
00187 /*
00188 * class DOMDocument extends DOMNode 
00189 *
00190 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-i-Document
00191 * Since: 
00192 */
00193 
00194 const zend_function_entry php_dom_document_class_functions[] = { /* {{{ */
00195        PHP_FALIAS(createElement, dom_document_create_element, arginfo_dom_document_create_element)
00196        PHP_FALIAS(createDocumentFragment, dom_document_create_document_fragment, arginfo_dom_document_create_document_fragment)
00197        PHP_FALIAS(createTextNode, dom_document_create_text_node, arginfo_dom_document_create_text_node)
00198        PHP_FALIAS(createComment, dom_document_create_comment, arginfo_dom_document_create_comment)
00199        PHP_FALIAS(createCDATASection, dom_document_create_cdatasection, arginfo_dom_document_create_cdatasection)
00200        PHP_FALIAS(createProcessingInstruction, dom_document_create_processing_instruction, arginfo_dom_document_create_processing_instruction)
00201        PHP_FALIAS(createAttribute, dom_document_create_attribute, arginfo_dom_document_create_attribute)
00202        PHP_FALIAS(createEntityReference, dom_document_create_entity_reference, arginfo_dom_document_create_entity_reference)
00203        PHP_FALIAS(getElementsByTagName, dom_document_get_elements_by_tag_name, arginfo_dom_document_get_elements_by_tag_name)
00204        PHP_FALIAS(importNode, dom_document_import_node, arginfo_dom_document_import_node)
00205        PHP_FALIAS(createElementNS, dom_document_create_element_ns, arginfo_dom_document_create_element_ns)
00206        PHP_FALIAS(createAttributeNS, dom_document_create_attribute_ns, arginfo_dom_document_create_attribute_ns)
00207        PHP_FALIAS(getElementsByTagNameNS, dom_document_get_elements_by_tag_name_ns, arginfo_dom_document_get_elements_by_tag_name_ns)
00208        PHP_FALIAS(getElementById, dom_document_get_element_by_id, arginfo_dom_document_get_element_by_id)
00209        PHP_FALIAS(adoptNode, dom_document_adopt_node, arginfo_dom_document_adopt_node)
00210        PHP_FALIAS(normalizeDocument, dom_document_normalize_document, arginfo_dom_document_normalize_document)
00211        PHP_FALIAS(renameNode, dom_document_rename_node, arginfo_dom_document_rename_node)
00212        PHP_ME(domdocument, load, arginfo_dom_document_load, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
00213        PHP_FALIAS(save, dom_document_save, arginfo_dom_document_save)
00214        PHP_ME(domdocument, loadXML, arginfo_dom_document_loadxml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
00215        PHP_FALIAS(saveXML, dom_document_savexml, arginfo_dom_document_savexml)
00216        PHP_ME(domdocument, __construct, arginfo_dom_document_construct, ZEND_ACC_PUBLIC)
00217        PHP_FALIAS(validate, dom_document_validate, arginfo_dom_document_validate)
00218        PHP_FALIAS(xinclude, dom_document_xinclude, arginfo_dom_document_xinclude)
00219 #if defined(LIBXML_HTML_ENABLED)
00220        PHP_ME(domdocument, loadHTML, arginfo_dom_document_loadhtml, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
00221        PHP_ME(domdocument, loadHTMLFile, arginfo_dom_document_loadhtmlfile, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
00222        PHP_FALIAS(saveHTML, dom_document_save_html, arginfo_dom_document_savehtml)
00223        PHP_FALIAS(saveHTMLFile, dom_document_save_html_file, arginfo_dom_document_savehtmlfile)
00224 #endif  /* defined(LIBXML_HTML_ENABLED) */
00225 #if defined(LIBXML_SCHEMAS_ENABLED)
00226        PHP_FALIAS(schemaValidate, dom_document_schema_validate_file, arginfo_dom_document_schema_validate_file)
00227        PHP_FALIAS(schemaValidateSource, dom_document_schema_validate_xml, arginfo_dom_document_schema_validate_xml)
00228        PHP_FALIAS(relaxNGValidate, dom_document_relaxNG_validate_file, arginfo_dom_document_relaxNG_validate_file)
00229        PHP_FALIAS(relaxNGValidateSource, dom_document_relaxNG_validate_xml, arginfo_dom_document_relaxNG_validate_xml)
00230 #endif
00231        PHP_ME(domdocument, registerNodeClass, arginfo_dom_document_registernodeclass, ZEND_ACC_PUBLIC)
00232        PHP_FE_END
00233 };
00234 /* }}} */
00235 
00236 /* {{{ docType       DOMDocumentType      
00237 readonly=yes 
00238 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-B63ED1A31
00239 Since: 
00240 */
00241 int dom_document_doctype_read(dom_object *obj, zval **retval TSRMLS_DC)
00242 {
00243        xmlDoc *docp;
00244        xmlDtdPtr dtdptr;
00245        int ret;
00246 
00247        docp = (xmlDocPtr) dom_object_get_node(obj);
00248 
00249        if (docp == NULL) {
00250               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00251               return FAILURE;
00252        }
00253 
00254        ALLOC_ZVAL(*retval);
00255 
00256        dtdptr = xmlGetIntSubset(docp);
00257        if (!dtdptr) {
00258               ZVAL_NULL(*retval);
00259               return SUCCESS;
00260        }
00261 
00262        if (NULL == (*retval = php_dom_create_object((xmlNodePtr) dtdptr, &ret, NULL, *retval, obj TSRMLS_CC))) {
00263               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
00264               return FAILURE;
00265        }
00266        return SUCCESS;
00267        
00268 }
00269 
00270 /* }}} */
00271 
00272 /* {{{ implementation       DOMImplementation    
00273 readonly=yes 
00274 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1B793EBA
00275 Since: 
00276 */
00277 int dom_document_implementation_read(dom_object *obj, zval **retval TSRMLS_DC)
00278 {
00279        ALLOC_ZVAL(*retval);
00280        php_dom_create_implementation(retval TSRMLS_CC);
00281        return SUCCESS;
00282 }
00283 
00284 /* }}} */
00285 
00286 /* {{{ documentElement      DOMElement    
00287 readonly=yes 
00288 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-87CD092
00289 Since: 
00290 */
00291 int dom_document_document_element_read(dom_object *obj, zval **retval TSRMLS_DC)
00292 {
00293        xmlDoc *docp;
00294        xmlNode *root;
00295        int ret;
00296 
00297        docp = (xmlDocPtr) dom_object_get_node(obj);
00298 
00299        if (docp == NULL) {
00300               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00301               return FAILURE;
00302        }
00303 
00304        ALLOC_ZVAL(*retval);
00305 
00306        root = xmlDocGetRootElement(docp);
00307        if (!root) {
00308               ZVAL_NULL(*retval);
00309               return SUCCESS;
00310        }
00311 
00312        if (NULL == (*retval = php_dom_create_object(root, &ret, NULL, *retval, obj TSRMLS_CC))) {
00313               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create required DOM object");
00314               return FAILURE;
00315        }
00316        return SUCCESS;
00317 }
00318 
00319 /* }}} */
00320 
00321 /* {{{ encoding      string
00322 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-encoding
00323 Since: DOM Level 3
00324 */
00325 int dom_document_encoding_read(dom_object *obj, zval **retval TSRMLS_DC)
00326 {
00327        xmlDoc *docp;
00328        char *encoding;
00329 
00330        docp = (xmlDocPtr) dom_object_get_node(obj);
00331 
00332        if (docp == NULL) {
00333               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00334               return FAILURE;
00335        }
00336 
00337        encoding = (char *) docp->encoding;
00338        ALLOC_ZVAL(*retval);
00339 
00340        if (encoding != NULL) {
00341               ZVAL_STRING(*retval, encoding, 1);
00342        } else {
00343               ZVAL_NULL(*retval);
00344        }
00345 
00346        return SUCCESS;
00347 }
00348 
00349 int dom_document_encoding_write(dom_object *obj, zval *newval TSRMLS_DC)
00350 {
00351        zval value_copy;
00352        xmlDoc *docp;
00353        xmlCharEncodingHandlerPtr handler;
00354 
00355        docp = (xmlDocPtr) dom_object_get_node(obj);
00356 
00357        if (docp == NULL) {
00358               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00359               return FAILURE;
00360        }
00361 
00362        if (newval->type != IS_STRING) {
00363               if(Z_REFCOUNT_P(newval) > 1) {
00364                      value_copy = *newval;
00365                      zval_copy_ctor(&value_copy);
00366                      newval = &value_copy;
00367               }
00368               convert_to_string(newval);
00369        }
00370 
00371        handler = xmlFindCharEncodingHandler(Z_STRVAL_P(newval));
00372 
00373     if (handler != NULL) {
00374               xmlCharEncCloseFunc(handler);
00375               if (docp->encoding != NULL) {
00376                      xmlFree((xmlChar *)docp->encoding);
00377               }
00378               docp->encoding = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
00379     } else {
00380               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Document Encoding");
00381     }
00382 
00383        if (newval == &value_copy) {
00384               zval_dtor(newval);
00385        }
00386 
00387        return SUCCESS;
00388 }
00389 
00390 /* }}} */
00391 
00392 /* {{{ standalone    boolean       
00393 readonly=no 
00394 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-standalone
00395 Since: DOM Level 3
00396 */
00397 int dom_document_standalone_read(dom_object *obj, zval **retval TSRMLS_DC)
00398 {
00399        xmlDoc *docp;
00400        int standalone;
00401 
00402        docp = (xmlDocPtr) dom_object_get_node(obj);
00403 
00404        if (docp == NULL) {
00405               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00406               return FAILURE;
00407        }
00408 
00409        ALLOC_ZVAL(*retval);
00410        standalone = docp->standalone;
00411        ZVAL_BOOL(*retval, standalone);
00412 
00413        return SUCCESS;
00414 }
00415 
00416 int dom_document_standalone_write(dom_object *obj, zval *newval TSRMLS_DC)
00417 {
00418        zval value_copy;
00419        xmlDoc *docp;
00420        int standalone;
00421 
00422        docp = (xmlDocPtr) dom_object_get_node(obj);
00423 
00424        if (docp == NULL) {
00425               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00426               return FAILURE;
00427        }
00428 
00429        if(Z_REFCOUNT_P(newval) > 1) {
00430               value_copy = *newval;
00431               zval_copy_ctor(&value_copy);
00432               newval = &value_copy;
00433        }
00434        convert_to_long(newval);
00435 
00436        standalone = Z_LVAL_P(newval);
00437     if (standalone > 0) {
00438         docp->standalone = 1;
00439     }
00440     else if (standalone < 0) {
00441         docp->standalone = -1;
00442     }
00443     else {
00444         docp->standalone = 0;
00445     }
00446 
00447        if (newval == &value_copy) {
00448               zval_dtor(newval);
00449        }
00450 
00451        return SUCCESS;
00452 }
00453 
00454 /* }}} */
00455 
00456 /* {{{ version       string 
00457 readonly=no
00458 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-version
00459 Since: DOM Level 3
00460 */
00461 int dom_document_version_read(dom_object *obj, zval **retval TSRMLS_DC)
00462 {
00463        xmlDoc *docp;
00464        char *version;
00465 
00466        docp = (xmlDocPtr) dom_object_get_node(obj);
00467 
00468        if (docp == NULL) {
00469               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00470               return FAILURE;
00471        }
00472 
00473        version = (char *) docp->version;
00474        ALLOC_ZVAL(*retval);
00475 
00476        if (version != NULL) {
00477               ZVAL_STRING(*retval, version, 1);
00478        } else {
00479               ZVAL_NULL(*retval);
00480        }
00481 
00482        return SUCCESS;
00483 }
00484 
00485 int dom_document_version_write(dom_object *obj, zval *newval TSRMLS_DC)
00486 {
00487        zval value_copy;
00488        xmlDoc *docp;
00489 
00490        docp = (xmlDocPtr) dom_object_get_node(obj);
00491 
00492        if (docp == NULL) {
00493               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00494               return FAILURE;
00495        }
00496 
00497        if (docp->version != NULL) {
00498               xmlFree((xmlChar *) docp->version );
00499        }
00500 
00501        if (newval->type != IS_STRING) {
00502               if(Z_REFCOUNT_P(newval) > 1) {
00503                      value_copy = *newval;
00504                      zval_copy_ctor(&value_copy);
00505                      newval = &value_copy;
00506               }
00507               convert_to_string(newval);
00508        }
00509 
00510        docp->version = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
00511 
00512        if (newval == &value_copy) {
00513               zval_dtor(newval);
00514        }
00515 
00516        return SUCCESS;
00517 }
00518 
00519 /* }}} */
00520 
00521 /* {{{ strictErrorChecking  boolean       
00522 readonly=no 
00523 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-strictErrorChecking
00524 Since: DOM Level 3
00525 */
00526 int dom_document_strict_error_checking_read(dom_object *obj, zval **retval TSRMLS_DC)
00527 {
00528        dom_doc_propsptr doc_prop;
00529 
00530        ALLOC_ZVAL(*retval);
00531        if (obj->document) {
00532               doc_prop = dom_get_doc_props(obj->document);
00533               ZVAL_BOOL(*retval, doc_prop->stricterror);
00534        } else {
00535               ZVAL_FALSE(*retval);
00536        }
00537        return SUCCESS;
00538 }
00539 
00540 int dom_document_strict_error_checking_write(dom_object *obj, zval *newval TSRMLS_DC)
00541 {
00542        zval value_copy;
00543        dom_doc_propsptr doc_prop;
00544 
00545        if(Z_REFCOUNT_P(newval) > 1) {
00546               value_copy = *newval;
00547               zval_copy_ctor(&value_copy);
00548               newval = &value_copy;
00549        }
00550        convert_to_boolean(newval);
00551 
00552        if (obj->document) {
00553               doc_prop = dom_get_doc_props(obj->document);
00554               doc_prop->stricterror = Z_LVAL_P(newval);
00555        }
00556 
00557        if (newval == &value_copy) {
00558               zval_dtor(newval);
00559        }
00560 
00561        return SUCCESS;
00562 }
00563 
00564 /* }}} */
00565 
00566 /* {{{ formatOutput  boolean       
00567 readonly=no
00568 */
00569 int dom_document_format_output_read(dom_object *obj, zval **retval TSRMLS_DC)
00570 {
00571        dom_doc_propsptr doc_prop;
00572 
00573        ALLOC_ZVAL(*retval);
00574        if (obj->document) {
00575               doc_prop = dom_get_doc_props(obj->document);
00576               ZVAL_BOOL(*retval, doc_prop->formatoutput);
00577        } else {
00578               ZVAL_FALSE(*retval);
00579        }
00580        return SUCCESS;
00581 }
00582 
00583 int dom_document_format_output_write(dom_object *obj, zval *newval TSRMLS_DC)
00584 {
00585        zval value_copy;
00586        dom_doc_propsptr doc_prop;
00587 
00588        if(Z_REFCOUNT_P(newval) > 1) {
00589               value_copy = *newval;
00590               zval_copy_ctor(&value_copy);
00591               newval = &value_copy;
00592        }
00593        convert_to_boolean(newval);
00594 
00595        if (obj->document) {
00596               doc_prop = dom_get_doc_props(obj->document);
00597               doc_prop->formatoutput = Z_LVAL_P(newval);
00598        }
00599 
00600        if (newval == &value_copy) {
00601               zval_dtor(newval);
00602        }
00603 
00604        return SUCCESS;
00605 }
00606 /* }}} */
00607 
00608 /* {{{ validateOnParse      boolean       
00609 readonly=no
00610 */
00611 int    dom_document_validate_on_parse_read(dom_object *obj, zval **retval TSRMLS_DC)
00612 {
00613        dom_doc_propsptr doc_prop;
00614 
00615        ALLOC_ZVAL(*retval);
00616        if (obj->document) {
00617               doc_prop = dom_get_doc_props(obj->document);
00618               ZVAL_BOOL(*retval, doc_prop->validateonparse);
00619        } else {
00620               ZVAL_FALSE(*retval);
00621        }
00622        return SUCCESS;
00623 }
00624 
00625 int dom_document_validate_on_parse_write(dom_object *obj, zval *newval TSRMLS_DC)
00626 {
00627        zval value_copy;
00628        dom_doc_propsptr doc_prop;
00629 
00630        if(Z_REFCOUNT_P(newval) > 1) {
00631               value_copy = *newval;
00632               zval_copy_ctor(&value_copy);
00633               newval = &value_copy;
00634        }
00635        convert_to_boolean(newval);
00636 
00637        if (obj->document) {
00638               doc_prop = dom_get_doc_props(obj->document);
00639               doc_prop->validateonparse = Z_LVAL_P(newval);
00640        }
00641 
00642        if (newval == &value_copy) {
00643               zval_dtor(newval);
00644        }
00645 
00646        return SUCCESS;
00647 }
00648 /* }}} */
00649 
00650 /* {{{ resolveExternals     boolean       
00651 readonly=no
00652 */
00653 int dom_document_resolve_externals_read(dom_object *obj, zval **retval TSRMLS_DC)
00654 {
00655        dom_doc_propsptr doc_prop;
00656 
00657        ALLOC_ZVAL(*retval);
00658        if (obj->document) {
00659               doc_prop = dom_get_doc_props(obj->document);
00660               ZVAL_BOOL(*retval, doc_prop->resolveexternals);
00661        } else {
00662               ZVAL_FALSE(*retval);
00663        }
00664        return SUCCESS;
00665 }
00666 
00667 int dom_document_resolve_externals_write(dom_object *obj, zval *newval TSRMLS_DC)
00668 {
00669        zval value_copy;
00670        dom_doc_propsptr doc_prop;
00671 
00672        if(Z_REFCOUNT_P(newval) > 1) {
00673               value_copy = *newval;
00674               zval_copy_ctor(&value_copy);
00675               newval = &value_copy;
00676        }
00677        convert_to_boolean(newval);
00678 
00679        if (obj->document) {
00680               doc_prop = dom_get_doc_props(obj->document);
00681               doc_prop->resolveexternals = Z_LVAL_P(newval);
00682        }
00683 
00684        if (newval == &value_copy) {
00685               zval_dtor(newval);
00686        }
00687 
00688        return SUCCESS;
00689 }
00690 /* }}} */
00691 
00692 /* {{{ preserveWhiteSpace   boolean       
00693 readonly=no
00694 */
00695 int dom_document_preserve_whitespace_read(dom_object *obj, zval **retval TSRMLS_DC)
00696 {
00697        dom_doc_propsptr doc_prop;
00698 
00699        ALLOC_ZVAL(*retval);
00700        if (obj->document) {
00701               doc_prop = dom_get_doc_props(obj->document);
00702               ZVAL_BOOL(*retval, doc_prop->preservewhitespace);
00703        } else {
00704               ZVAL_FALSE(*retval);
00705        }
00706        return SUCCESS;
00707 }
00708 
00709 int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval TSRMLS_DC)
00710 {
00711        zval value_copy;
00712        dom_doc_propsptr doc_prop;
00713 
00714        if(Z_REFCOUNT_P(newval) > 1) {
00715               value_copy = *newval;
00716               zval_copy_ctor(&value_copy);
00717               newval = &value_copy;
00718        }
00719        convert_to_boolean(newval);
00720 
00721        if (obj->document) {
00722               doc_prop = dom_get_doc_props(obj->document);
00723               doc_prop->preservewhitespace = Z_LVAL_P(newval);
00724        }
00725 
00726        if (newval == &value_copy) {
00727               zval_dtor(newval);
00728        }
00729 
00730        return SUCCESS;
00731 }
00732 /* }}} */
00733 
00734 /* {{{ recover       boolean       
00735 readonly=no
00736 */
00737 int dom_document_recover_read(dom_object *obj, zval **retval TSRMLS_DC)
00738 {
00739        dom_doc_propsptr doc_prop;
00740 
00741        ALLOC_ZVAL(*retval);
00742        if (obj->document) {
00743               doc_prop = dom_get_doc_props(obj->document);
00744               ZVAL_BOOL(*retval, doc_prop->recover);
00745        } else {
00746               ZVAL_FALSE(*retval);
00747        }
00748        return SUCCESS;
00749 }
00750 
00751 int dom_document_recover_write(dom_object *obj, zval *newval TSRMLS_DC)
00752 {
00753        zval value_copy;
00754        dom_doc_propsptr doc_prop;
00755 
00756        if(Z_REFCOUNT_P(newval) > 1) {
00757               value_copy = *newval;
00758               zval_copy_ctor(&value_copy);
00759               newval = &value_copy;
00760        }
00761        convert_to_boolean(newval);
00762 
00763        if (obj->document) {
00764               doc_prop = dom_get_doc_props(obj->document);
00765               doc_prop->recover = Z_LVAL_P(newval);
00766        }
00767 
00768        if (newval == &value_copy) {
00769               zval_dtor(newval);
00770        }
00771 
00772        return SUCCESS;
00773 }
00774 /* }}} */
00775 
00776 /* {{{ substituteEntities   boolean       
00777 readonly=no
00778 */
00779 int dom_document_substitue_entities_read(dom_object *obj, zval **retval TSRMLS_DC)
00780 {
00781        dom_doc_propsptr doc_prop;
00782 
00783        ALLOC_ZVAL(*retval);
00784        if (obj->document) {
00785               doc_prop = dom_get_doc_props(obj->document);
00786               ZVAL_BOOL(*retval, doc_prop->substituteentities);
00787        } else {
00788               ZVAL_FALSE(*retval);
00789        }
00790        return SUCCESS;
00791 }
00792 
00793 int dom_document_substitue_entities_write(dom_object *obj, zval *newval TSRMLS_DC)
00794 {
00795        zval value_copy;
00796        dom_doc_propsptr doc_prop;
00797 
00798        if(Z_REFCOUNT_P(newval) > 1) {
00799               value_copy = *newval;
00800               zval_copy_ctor(&value_copy);
00801               newval = &value_copy;
00802        }
00803        convert_to_boolean(newval);
00804 
00805        if (obj->document) {
00806               doc_prop = dom_get_doc_props(obj->document);
00807               doc_prop->substituteentities = Z_LVAL_P(newval);
00808        }
00809 
00810        if (newval == &value_copy) {
00811               zval_dtor(newval);
00812        }
00813 
00814        return SUCCESS;
00815 }
00816 /* }}} */
00817 
00818 /* {{{ documentURI   string 
00819 readonly=no 
00820 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-documentURI
00821 Since: DOM Level 3
00822 */
00823 int dom_document_document_uri_read(dom_object *obj, zval **retval TSRMLS_DC)
00824 {
00825        xmlDoc *docp;
00826        char *url;
00827 
00828        docp = (xmlDocPtr) dom_object_get_node(obj);
00829 
00830        if (docp == NULL) {
00831               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00832               return FAILURE;
00833        }
00834 
00835        ALLOC_ZVAL(*retval);
00836        url = (char *) docp->URL;
00837        if (url != NULL) {
00838               ZVAL_STRING(*retval, url, 1);
00839        } else {
00840               ZVAL_NULL(*retval);
00841        }
00842 
00843        return SUCCESS;
00844 }
00845 
00846 int dom_document_document_uri_write(dom_object *obj, zval *newval TSRMLS_DC)
00847 {
00848        zval value_copy;
00849        xmlDoc *docp;
00850 
00851        docp = (xmlDocPtr) dom_object_get_node(obj);
00852 
00853        if (docp == NULL) {
00854               php_dom_throw_error(INVALID_STATE_ERR, 0 TSRMLS_CC);
00855               return FAILURE;
00856        }
00857 
00858        if (docp->URL != NULL) {
00859               xmlFree((xmlChar *) docp->URL);
00860        }
00861 
00862        if (newval->type != IS_STRING) {
00863               if(Z_REFCOUNT_P(newval) > 1) {
00864                      value_copy = *newval;
00865                      zval_copy_ctor(&value_copy);
00866                      newval = &value_copy;
00867               }
00868               convert_to_string(newval);
00869        }
00870 
00871        docp->URL = xmlStrdup((const xmlChar *) Z_STRVAL_P(newval));
00872 
00873        if (newval == &value_copy) {
00874               zval_dtor(newval);
00875        }
00876 
00877        return SUCCESS;
00878 }
00879 
00880 /* }}} */
00881 
00882 /* {{{ config DOMConfiguration     
00883 readonly=yes 
00884 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-config
00885 Since: DOM Level 3
00886 */
00887 int dom_document_config_read(dom_object *obj, zval **retval TSRMLS_DC)
00888 {
00889        ALLOC_ZVAL(*retval);
00890        ZVAL_NULL(*retval);
00891        return SUCCESS;
00892 }
00893 
00894 /* }}} */
00895 
00896 /* {{{ proto DOMElement dom_document_create_element(string tagName [, string value]);
00897 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-2141741547
00898 Since: 
00899 */
00900 PHP_FUNCTION(dom_document_create_element)
00901 {
00902        zval *id, *rv = NULL;
00903        xmlNode *node;
00904        xmlDocPtr docp;
00905        dom_object *intern;
00906        int ret, name_len, value_len;
00907        char *name, *value = NULL;
00908 
00909        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
00910               return;
00911        }
00912 
00913        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
00914 
00915        if (xmlValidateName((xmlChar *) name, 0) != 0) {
00916               php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
00917               RETURN_FALSE;
00918        }
00919 
00920        node = xmlNewDocNode(docp, NULL, name, value);
00921        if (!node) {
00922               RETURN_FALSE;
00923        }
00924 
00925        DOM_RET_OBJ(rv, node, &ret, intern);
00926 }
00927 /* }}} end dom_document_create_element */
00928 
00929 /* {{{ proto DOMDocumentFragment dom_document_create_document_fragment();
00930 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-35CB04B5
00931 Since: 
00932 */
00933 PHP_FUNCTION(dom_document_create_document_fragment)
00934 {
00935        zval *id, *rv = NULL;
00936        xmlNode *node;
00937        xmlDocPtr docp;
00938        dom_object *intern;
00939        int ret;
00940 
00941        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
00942               return;
00943        }
00944 
00945        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
00946 
00947        node =  xmlNewDocFragment(docp);
00948        if (!node) {
00949               RETURN_FALSE;
00950        }
00951 
00952        DOM_RET_OBJ(rv, node, &ret, intern);
00953 }
00954 /* }}} end dom_document_create_document_fragment */
00955 
00956 /* {{{ proto DOMText dom_document_create_text_node(string data);
00957 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1975348127
00958 Since: 
00959 */
00960 PHP_FUNCTION(dom_document_create_text_node)
00961 {
00962        zval *id, *rv = NULL;
00963        xmlNode *node;
00964        xmlDocPtr docp;
00965        int ret, value_len;
00966        dom_object *intern;
00967        char *value;
00968 
00969        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
00970               return;
00971        }
00972 
00973        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
00974 
00975        node = xmlNewDocText(docp, (xmlChar *) value);
00976        if (!node) {
00977               RETURN_FALSE;
00978        }
00979 
00980        DOM_RET_OBJ(rv, node, &ret, intern);
00981 }
00982 /* }}} end dom_document_create_text_node */
00983 
00984 /* {{{ proto DOMComment dom_document_create_comment(string data);
00985 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1334481328
00986 Since: 
00987 */
00988 PHP_FUNCTION(dom_document_create_comment)
00989 {
00990        zval *id, *rv = NULL;
00991        xmlNode *node;
00992        xmlDocPtr docp;
00993        int ret, value_len;
00994        dom_object *intern;
00995        char *value;
00996 
00997        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
00998               return;
00999        }
01000 
01001        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01002 
01003        node = xmlNewDocComment(docp, (xmlChar *) value);
01004        if (!node) {
01005               RETURN_FALSE;
01006        }
01007 
01008        DOM_RET_OBJ(rv, node, &ret, intern);
01009 }
01010 /* }}} end dom_document_create_comment */
01011 
01012 /* {{{ proto DOMCdataSection dom_document_create_cdatasection(string data);
01013 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D26C0AF8
01014 Since: 
01015 */
01016 PHP_FUNCTION(dom_document_create_cdatasection)
01017 {
01018        zval *id, *rv = NULL;
01019        xmlNode *node;
01020        xmlDocPtr docp;
01021        int ret, value_len;
01022        dom_object *intern;
01023        char *value;
01024 
01025        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &value, &value_len) == FAILURE) {
01026               return;
01027        }
01028 
01029        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01030 
01031        node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
01032        if (!node) {
01033               RETURN_FALSE;
01034        }
01035 
01036        DOM_RET_OBJ(rv, node, &ret, intern);
01037 }
01038 /* }}} end dom_document_create_cdatasection */
01039 
01040 /* {{{ proto DOMProcessingInstruction dom_document_create_processing_instruction(string target, string data);
01041 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-135944439
01042 Since: 
01043 */
01044 PHP_FUNCTION(dom_document_create_processing_instruction)
01045 {
01046        zval *id, *rv = NULL;
01047        xmlNode *node;
01048        xmlDocPtr docp;
01049        int ret, value_len, name_len = 0;
01050        dom_object *intern;
01051        char *name, *value = NULL;
01052 
01053        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_document_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
01054               return;
01055        }
01056 
01057        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01058 
01059        if (xmlValidateName((xmlChar *) name, 0) != 0) {
01060               php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01061               RETURN_FALSE;
01062        }
01063 
01064        node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
01065        if (!node) {
01066               RETURN_FALSE;
01067        }
01068 
01069        node->doc = docp;
01070 
01071        DOM_RET_OBJ(rv, node, &ret, intern);
01072 }
01073 /* }}} end dom_document_create_processing_instruction */
01074 
01075 /* {{{ proto DOMAttr dom_document_create_attribute(string name);
01076 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1084891198
01077 Since: 
01078 */
01079 PHP_FUNCTION(dom_document_create_attribute)
01080 {
01081        zval *id, *rv = NULL;
01082        xmlAttrPtr node;
01083        xmlDocPtr docp;
01084        int ret, name_len;
01085        dom_object *intern;
01086        char *name;
01087 
01088        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
01089               return;
01090        }
01091 
01092        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01093 
01094        if (xmlValidateName((xmlChar *) name, 0) != 0) {
01095               php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01096               RETURN_FALSE;
01097        }
01098 
01099        node = xmlNewDocProp(docp, (xmlChar *) name, NULL);
01100        if (!node) {
01101               RETURN_FALSE;
01102        }
01103 
01104        DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret, intern);
01105 
01106 }
01107 /* }}} end dom_document_create_attribute */
01108 
01109 /* {{{ proto DOMEntityReference dom_document_create_entity_reference(string name);
01110 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-392B75AE
01111 Since: 
01112 */
01113 PHP_FUNCTION(dom_document_create_entity_reference)
01114 {
01115        zval *id, *rv = NULL;
01116        xmlNode *node;
01117        xmlDocPtr docp = NULL;
01118        dom_object *intern;
01119        int ret, name_len;
01120        char *name;
01121 
01122        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
01123               return;
01124        }
01125 
01126        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01127 
01128        if (xmlValidateName((xmlChar *) name, 0) != 0) {
01129               php_dom_throw_error(INVALID_CHARACTER_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01130               RETURN_FALSE;
01131        }
01132 
01133        node = xmlNewReference(docp, name);
01134        if (!node) {
01135               RETURN_FALSE;
01136        }
01137 
01138        DOM_RET_OBJ(rv, (xmlNodePtr) node, &ret, intern);
01139 }
01140 /* }}} end dom_document_create_entity_reference */
01141 
01142 /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name(string tagname);
01143 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-A6C9094
01144 Since: 
01145 */
01146 PHP_FUNCTION(dom_document_get_elements_by_tag_name)
01147 {
01148        zval *id;
01149        xmlDocPtr docp;
01150        int name_len;
01151        dom_object *intern, *namednode;
01152        char *name;
01153        xmlChar *local;
01154 
01155        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &name, &name_len) == FAILURE) {
01156               return;
01157        }
01158 
01159        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01160 
01161        php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
01162        namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
01163        local = xmlCharStrndup(name, name_len);
01164        dom_namednode_iter(intern, 0, namednode, NULL, local, NULL TSRMLS_CC);
01165 }
01166 /* }}} end dom_document_get_elements_by_tag_name */
01167 
01168 /* {{{ proto DOMNode dom_document_import_node(DOMNode importedNode, boolean deep);
01169 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Core-Document-importNode
01170 Since: DOM Level 2
01171 */
01172 PHP_FUNCTION(dom_document_import_node)
01173 {
01174        zval *rv = NULL;
01175        zval *id, *node;
01176        xmlDocPtr docp;
01177        xmlNodePtr nodep, retnodep;
01178        dom_object *intern, *nodeobj;
01179        int ret; 
01180        long recursive = 0;
01181 
01182        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO|l", &id, dom_document_class_entry, &node, dom_node_class_entry, &recursive) == FAILURE) {
01183               return;
01184        }
01185 
01186        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01187 
01188        DOM_GET_OBJ(nodep, node, xmlNodePtr, nodeobj);
01189 
01190        if (nodep->type == XML_HTML_DOCUMENT_NODE || nodep->type == XML_DOCUMENT_NODE 
01191               || nodep->type == XML_DOCUMENT_TYPE_NODE) {
01192               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot import: Node Type Not Supported");
01193               RETURN_FALSE;
01194        }
01195 
01196        if (nodep->doc == docp) {
01197               retnodep = nodep;
01198        } else {
01199               if ((recursive == 0) && (nodep->type == XML_ELEMENT_NODE)) {
01200                      recursive = 2;
01201               }
01202               retnodep = xmlDocCopyNode(nodep, docp, recursive);
01203               if (!retnodep) {
01204                      RETURN_FALSE;
01205               }
01206 
01207               if ((retnodep->type == XML_ATTRIBUTE_NODE) && (nodep->ns != NULL)) {
01208                      xmlNsPtr nsptr = NULL;
01209                      xmlNodePtr root = xmlDocGetRootElement(docp);
01210 
01211                      nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href);
01212                      if (nsptr == NULL) {
01213                             int errorcode;
01214                             nsptr = dom_get_ns(root, nodep->ns->href, &errorcode, nodep->ns->prefix);
01215                      }
01216                      xmlSetNs(retnodep, nsptr);
01217               }
01218        }
01219 
01220        DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern);
01221 }
01222 /* }}} end dom_document_import_node */
01223 
01224 /* {{{ proto DOMElement dom_document_create_element_ns(string namespaceURI, string qualifiedName [,string value]);
01225 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrElNS
01226 Since: DOM Level 2
01227 */
01228 PHP_FUNCTION(dom_document_create_element_ns)
01229 {
01230        zval *id, *rv = NULL;
01231        xmlDocPtr docp;
01232        xmlNodePtr nodep = NULL;
01233        xmlNsPtr nsptr = NULL;
01234        int ret, uri_len = 0, name_len = 0, value_len = 0;
01235        char *uri, *name, *value = NULL;
01236        char *localname = NULL, *prefix = NULL;
01237        int errorcode;
01238        dom_object *intern;
01239 
01240        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s|s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len, &value, &value_len) == FAILURE) {
01241               return;
01242        }
01243 
01244        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01245 
01246        errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
01247 
01248        if (errorcode == 0) {
01249               if (xmlValidateName((xmlChar *) localname, 0) == 0) {
01250                      nodep = xmlNewDocNode (docp, NULL, localname, value);
01251                      if (nodep != NULL && uri != NULL) {
01252                             nsptr = xmlSearchNsByHref (nodep->doc, nodep, uri);
01253                             if (nsptr == NULL) {
01254                                    nsptr = dom_get_ns(nodep, uri, &errorcode, prefix);
01255                             }
01256                             xmlSetNs(nodep, nsptr);
01257                      }
01258               } else {
01259                      errorcode = INVALID_CHARACTER_ERR;
01260               }
01261        }
01262 
01263        xmlFree(localname);
01264        if (prefix != NULL) {
01265               xmlFree(prefix);
01266        }
01267 
01268        if (errorcode != 0) {
01269               if (nodep != NULL) {
01270                      xmlFreeNode(nodep);
01271               }
01272               php_dom_throw_error(errorcode, dom_get_strict_error(intern->document) TSRMLS_CC);
01273               RETURN_FALSE;
01274        }
01275 
01276        if (nodep == NULL) {
01277               RETURN_FALSE;
01278        }
01279 
01280        
01281        nodep->ns = nsptr;
01282 
01283        DOM_RET_OBJ(rv, nodep, &ret, intern);
01284 }
01285 /* }}} end dom_document_create_element_ns */
01286 
01287 /* {{{ proto DOMAttr dom_document_create_attribute_ns(string namespaceURI, string qualifiedName);
01288 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-DocCrAttrNS
01289 Since: DOM Level 2
01290 */
01291 PHP_FUNCTION(dom_document_create_attribute_ns)
01292 {
01293        zval *id, *rv = NULL;
01294        xmlDocPtr docp;
01295        xmlNodePtr nodep = NULL, root;
01296        xmlNsPtr nsptr;
01297        int ret, uri_len = 0, name_len = 0;
01298        char *uri, *name;
01299        char *localname = NULL, *prefix = NULL;
01300        dom_object *intern;
01301        int errorcode;
01302 
01303        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os!s", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
01304               return;
01305        }
01306 
01307        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01308 
01309        root = xmlDocGetRootElement(docp);
01310        if (root != NULL) {
01311               errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len);
01312               if (errorcode == 0) {
01313                      if (xmlValidateName((xmlChar *) localname, 0) == 0) {
01314                             nodep = (xmlNodePtr) xmlNewDocProp(docp, localname, NULL);
01315                             if (nodep != NULL && uri_len > 0) {
01316                                    nsptr = xmlSearchNsByHref (nodep->doc, root, uri);
01317                                    if (nsptr == NULL) {
01318                                           nsptr = dom_get_ns(root, uri, &errorcode, prefix);
01319                                    }
01320                                    xmlSetNs(nodep, nsptr);
01321                             }
01322                      } else {
01323                             errorcode = INVALID_CHARACTER_ERR;
01324                      }
01325               }
01326        } else {
01327               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Document Missing Root Element");
01328               RETURN_FALSE;
01329        }
01330 
01331        xmlFree(localname);
01332        if (prefix != NULL) {
01333               xmlFree(prefix);
01334        }
01335 
01336        if (errorcode != 0) {
01337               if (nodep != NULL) {
01338                      xmlFreeProp((xmlAttrPtr) nodep);
01339               }
01340               php_dom_throw_error(errorcode, dom_get_strict_error(intern->document) TSRMLS_CC);
01341               RETURN_FALSE;
01342        }
01343 
01344        if (nodep == NULL) {
01345               RETURN_FALSE;
01346        }
01347 
01348        DOM_RET_OBJ(rv, nodep, &ret, intern);
01349 }
01350 /* }}} end dom_document_create_attribute_ns */
01351 
01352 /* {{{ proto DOMNodeList dom_document_get_elements_by_tag_name_ns(string namespaceURI, string localName);
01353 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBTNNS
01354 Since: DOM Level 2
01355 */
01356 PHP_FUNCTION(dom_document_get_elements_by_tag_name_ns)
01357 {
01358        zval *id;
01359        xmlDocPtr docp;
01360        int uri_len, name_len;
01361        dom_object *intern, *namednode;
01362        char *uri, *name;
01363        xmlChar *local, *nsuri;
01364 
01365        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss", &id, dom_document_class_entry, &uri, &uri_len, &name, &name_len) == FAILURE) {
01366               return;
01367        }
01368 
01369        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01370 
01371        php_dom_create_interator(return_value, DOM_NODELIST TSRMLS_CC);
01372        namednode = (dom_object *)zend_objects_get_address(return_value TSRMLS_CC);
01373        local = xmlCharStrndup(name, name_len);
01374        nsuri = xmlCharStrndup(uri, uri_len);
01375        dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri TSRMLS_CC);
01376 }
01377 /* }}} end dom_document_get_elements_by_tag_name_ns */
01378 
01379 /* {{{ proto DOMElement dom_document_get_element_by_id(string elementId);
01380 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-getElBId
01381 Since: DOM Level 2
01382 */
01383 PHP_FUNCTION(dom_document_get_element_by_id)
01384 {
01385        zval *id, *rv = NULL;
01386        xmlDocPtr docp;
01387        xmlAttrPtr  attrp;
01388        int ret, idname_len;
01389        dom_object *intern;
01390        char *idname;
01391 
01392        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &idname, &idname_len) == FAILURE) {
01393               return;
01394        }
01395 
01396        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01397 
01398        attrp = xmlGetID(docp, (xmlChar *) idname);
01399 
01400        if (attrp && attrp->parent) {
01401               DOM_RET_OBJ(rv, (xmlNodePtr) attrp->parent, &ret, intern);
01402        } else {
01403               RETVAL_NULL();
01404        }
01405 
01406 }
01407 /* }}} end dom_document_get_element_by_id */
01408 
01409 /* {{{ proto DOMNode dom_document_adopt_node(DOMNode source);
01410 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-adoptNode
01411 Since: DOM Level 3
01412 */
01413 PHP_FUNCTION(dom_document_adopt_node)
01414 {
01415  DOM_NOT_IMPLEMENTED();
01416 }
01417 /* }}} end dom_document_adopt_node */
01418 
01419 /* {{{ proto void dom_document_normalize_document();
01420 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-normalizeDocument
01421 Since: DOM Level 3
01422 */
01423 PHP_FUNCTION(dom_document_normalize_document)
01424 {
01425        zval *id;
01426        xmlDocPtr docp;
01427        dom_object *intern;
01428 
01429        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
01430               return;
01431        }
01432 
01433        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01434 
01435        dom_normalize((xmlNodePtr) docp TSRMLS_CC);
01436 }
01437 /* }}} end dom_document_normalize_document */
01438 
01439 /* {{{ proto DOMNode dom_document_rename_node(node n, string namespaceURI, string qualifiedName);
01440 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-renameNode
01441 Since: DOM Level 3
01442 */
01443 PHP_FUNCTION(dom_document_rename_node)
01444 {
01445  DOM_NOT_IMPLEMENTED();
01446 }
01447 /* }}} end dom_document_rename_node */
01448 
01449 /* {{{ proto void DOMDocument::__construct([string version], [string encoding]); */
01450 PHP_METHOD(domdocument, __construct)
01451 {
01452 
01453        zval *id;
01454        xmlDoc *docp = NULL, *olddoc;
01455        dom_object *intern;
01456        char *encoding, *version = NULL;
01457        int encoding_len = 0, version_len = 0, refcount;
01458        zend_error_handling error_handling;
01459 
01460        zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
01461        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ss", &id, dom_document_class_entry, &version, &version_len, &encoding, &encoding_len) == FAILURE) {
01462               zend_restore_error_handling(&error_handling TSRMLS_CC);
01463               return;
01464        }
01465 
01466        zend_restore_error_handling(&error_handling TSRMLS_CC);
01467        docp = xmlNewDoc(version);
01468 
01469        if (!docp) {
01470               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
01471               RETURN_FALSE;
01472        }
01473 
01474        if (encoding_len > 0) {
01475               docp->encoding = (const xmlChar*)xmlStrdup(encoding);
01476        }
01477 
01478        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
01479        if (intern != NULL) {
01480               olddoc = (xmlDocPtr) dom_object_get_node(intern);
01481               if (olddoc != NULL) {
01482                      php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
01483                      refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
01484                      if (refcount != 0) {
01485                             olddoc->_private = NULL;
01486                      }
01487               }
01488               intern->document = NULL;
01489               if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp TSRMLS_CC) == -1) {
01490                      RETURN_FALSE;
01491               }
01492               php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern TSRMLS_CC);
01493        }
01494 }
01495 /* }}} end DOMDocument::__construct */
01496 
01497 char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len  TSRMLS_DC) /* {{{ */
01498 {
01499        xmlURI *uri;
01500        xmlChar *escsource;
01501        char *file_dest;
01502        int isFileUri = 0;
01503 
01504        uri = xmlCreateURI();
01505        escsource = xmlURIEscapeStr(source, ":");
01506        xmlParseURIReference(uri, escsource);
01507        xmlFree(escsource);
01508 
01509        if (uri->scheme != NULL) {
01510               /* absolute file uris - libxml only supports localhost or empty host */
01511               if (strncasecmp(source, "file:///",8) == 0) {
01512                      isFileUri = 1;
01513 #ifdef PHP_WIN32
01514                      source += 8;
01515 #else
01516                      source += 7;
01517 #endif
01518               } else if (strncasecmp(source, "file://localhost/",17) == 0) {
01519                      isFileUri = 1;
01520 #ifdef PHP_WIN32
01521                      source += 17;
01522 #else
01523                      source += 16;
01524 #endif
01525               }
01526        }
01527 
01528        file_dest = source;
01529 
01530        if ((uri->scheme == NULL || isFileUri)) {
01531               /* XXX possible buffer overflow if VCWD_REALPATH does not know size of resolved_path */
01532               if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) {
01533                      xmlFreeURI(uri);
01534                      return NULL;
01535               }
01536               file_dest = resolved_path;
01537        }
01538 
01539        xmlFreeURI(uri);
01540 
01541        return file_dest;
01542 }
01543 /* }}} */
01544 
01545 static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int source_len, int options TSRMLS_DC) /* {{{ */
01546 {
01547     xmlDocPtr ret;
01548     xmlParserCtxtPtr ctxt = NULL;
01549        dom_doc_propsptr doc_props;
01550        dom_object *intern;
01551        php_libxml_ref_obj *document = NULL;
01552        int validate, recover, resolve_externals, keep_blanks, substitute_ent;
01553        int resolved_path_len;
01554        int old_error_reporting = 0;
01555        char *directory=NULL, resolved_path[MAXPATHLEN];
01556 
01557        if (id != NULL) {
01558               intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
01559               document = intern->document;
01560        }
01561 
01562        doc_props = dom_get_doc_props(document);
01563        validate = doc_props->validateonparse;
01564        resolve_externals = doc_props->resolveexternals;
01565        keep_blanks = doc_props->preservewhitespace;
01566        substitute_ent = doc_props->substituteentities;
01567        recover = doc_props->recover;
01568 
01569        if (document == NULL) {
01570               efree(doc_props);
01571        }
01572 
01573        xmlInitParser();
01574 
01575        if (mode == DOM_LOAD_FILE) {
01576               char *file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
01577               if (file_dest) {
01578                      ctxt = xmlCreateFileParserCtxt(file_dest);
01579               }
01580               
01581        } else {
01582               ctxt = xmlCreateMemoryParserCtxt(source, source_len);
01583        }
01584 
01585        if (ctxt == NULL) {
01586               return(NULL);
01587        }
01588 
01589        /* If loading from memory, we need to set the base directory for the document */
01590        if (mode != DOM_LOAD_FILE) {
01591 #if HAVE_GETCWD
01592               directory = VCWD_GETCWD(resolved_path, MAXPATHLEN);
01593 #elif HAVE_GETWD
01594               directory = VCWD_GETWD(resolved_path);
01595 #endif
01596               if (directory) {
01597                      if(ctxt->directory != NULL) {
01598                             xmlFree((char *) ctxt->directory);
01599                      }
01600                      resolved_path_len = strlen(resolved_path);
01601                      if (resolved_path[resolved_path_len - 1] != DEFAULT_SLASH) {
01602                             resolved_path[resolved_path_len] = DEFAULT_SLASH;
01603                             resolved_path[++resolved_path_len] = '\0';
01604                      }
01605                      ctxt->directory = (char *) xmlCanonicPath((const xmlChar *) resolved_path);
01606               }
01607        }
01608 
01609        ctxt->vctxt.error = php_libxml_ctx_error;
01610        ctxt->vctxt.warning = php_libxml_ctx_warning;
01611 
01612        if (ctxt->sax != NULL) {
01613               ctxt->sax->error = php_libxml_ctx_error;
01614               ctxt->sax->warning = php_libxml_ctx_warning;
01615        }
01616 
01617        if (validate && ! (options & XML_PARSE_DTDVALID)) {
01618               options |= XML_PARSE_DTDVALID;
01619        }
01620        if (resolve_externals && ! (options & XML_PARSE_DTDATTR)) {
01621               options |= XML_PARSE_DTDATTR;
01622        }
01623        if (substitute_ent && ! (options & XML_PARSE_NOENT)) {
01624               options |= XML_PARSE_NOENT;
01625        }
01626        if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
01627               options |= XML_PARSE_NOBLANKS;
01628        }
01629 
01630        xmlCtxtUseOptions(ctxt, options);
01631 
01632        ctxt->recovery = recover;
01633        if (recover) {
01634               old_error_reporting = EG(error_reporting);
01635               EG(error_reporting) = old_error_reporting | E_WARNING;
01636        }
01637 
01638        xmlParseDocument(ctxt);
01639 
01640        if (ctxt->wellFormed || recover) {
01641               ret = ctxt->myDoc;
01642               if (ctxt->recovery) {
01643                      EG(error_reporting) = old_error_reporting;
01644               }
01645               /* If loading from memory, set the base reference uri for the document */
01646               if (ret && ret->URL == NULL && ctxt->directory != NULL) {
01647                      ret->URL = xmlStrdup(ctxt->directory);
01648               }
01649        } else {
01650               ret = NULL;
01651               xmlFreeDoc(ctxt->myDoc);
01652               ctxt->myDoc = NULL;
01653        }
01654 
01655        xmlFreeParserCtxt(ctxt);
01656 
01657        return(ret);
01658 }
01659 /* }}} */
01660 
01661 /* {{{ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) */
01662 static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
01663        zval *id, *rv = NULL;
01664        xmlDoc *docp = NULL, *newdoc;
01665        dom_doc_propsptr doc_prop;
01666        dom_object *intern;
01667        char *source;
01668        int source_len, refcount, ret;
01669        long options = 0;
01670 
01671        id = getThis();
01672        if (id != NULL && ! instanceof_function(Z_OBJCE_P(id), dom_document_class_entry TSRMLS_CC)) {
01673               id = NULL;
01674        }
01675 
01676        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) {
01677               return;
01678        }
01679 
01680        if (!source_len) {
01681               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
01682               RETURN_FALSE;
01683        }
01684 
01685        newdoc = dom_document_parser(id, mode, source, source_len, options TSRMLS_CC);
01686 
01687        if (!newdoc)
01688               RETURN_FALSE;
01689 
01690        if (id != NULL) {
01691               intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
01692               if (intern != NULL) {
01693                      docp = (xmlDocPtr) dom_object_get_node(intern);
01694                      doc_prop = NULL;
01695                      if (docp != NULL) {
01696                             php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
01697                             doc_prop = intern->document->doc_props;
01698                             intern->document->doc_props = NULL;
01699                             refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
01700                             if (refcount != 0) {
01701                                    docp->_private = NULL;
01702                             }
01703                      }
01704                      intern->document = NULL;
01705                      if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc TSRMLS_CC) == -1) {
01706                             RETURN_FALSE;
01707                      }
01708                      intern->document->doc_props = doc_prop;
01709               }
01710 
01711               php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern TSRMLS_CC);
01712 
01713               RETURN_TRUE;
01714        } else {
01715               DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL);
01716        }
01717 }
01718 /* }}} end dom_parser_document */
01719 
01720 /* {{{ proto DOMNode dom_document_load(string source [, int options]);
01721 URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-load
01722 Since: DOM Level 3
01723 */
01724 PHP_METHOD(domdocument, load)
01725 {
01726        dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
01727 }
01728 /* }}} end dom_document_load */
01729 
01730 /* {{{ proto DOMNode dom_document_loadxml(string source [, int options]);
01731 URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-loadXML
01732 Since: DOM Level 3
01733 */
01734 PHP_METHOD(domdocument, loadXML)
01735 {
01736        dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
01737 }
01738 /* }}} end dom_document_loadxml */
01739 
01740 /* {{{ proto int dom_document_save(string file);
01741 Convenience method to save to file
01742 */
01743 PHP_FUNCTION(dom_document_save)
01744 {
01745        zval *id;
01746        xmlDoc *docp;
01747        int file_len = 0, bytes, format, saveempty = 0;
01748        dom_object *intern;
01749        dom_doc_propsptr doc_props;
01750        char *file;
01751        long options = 0;
01752 
01753        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l", &id, dom_document_class_entry, &file, &file_len, &options) == FAILURE) {
01754               return;
01755        }
01756 
01757        if (file_len == 0) {
01758               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Filename");
01759               RETURN_FALSE;
01760        }
01761 
01762        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01763 
01764        /* encoding handled by property on doc */
01765 
01766        doc_props = dom_get_doc_props(intern->document);
01767        format = doc_props->formatoutput;
01768        if (options & LIBXML_SAVE_NOEMPTYTAG) {
01769               saveempty = xmlSaveNoEmptyTags;
01770               xmlSaveNoEmptyTags = 1;
01771        }
01772        bytes = xmlSaveFormatFileEnc(file, docp, NULL, format);
01773        if (options & LIBXML_SAVE_NOEMPTYTAG) {
01774               xmlSaveNoEmptyTags = saveempty;
01775        }
01776        if (bytes == -1) {
01777               RETURN_FALSE;
01778        }
01779        RETURN_LONG(bytes);
01780 }
01781 /* }}} end dom_document_save */
01782 
01783 /* {{{ proto string dom_document_savexml([node n]);
01784 URL: http://www.w3.org/TR/DOM-Level-3-LS/load-save.html#LS-DocumentLS-saveXML
01785 Since: DOM Level 3
01786 */
01787 PHP_FUNCTION(dom_document_savexml)
01788 {
01789        zval *id, *nodep = NULL;
01790        xmlDoc *docp;
01791        xmlNode *node;
01792        xmlBufferPtr buf;
01793        xmlChar *mem;
01794        dom_object *intern, *nodeobj;
01795        dom_doc_propsptr doc_props;
01796        int size, format, saveempty = 0;
01797        long options = 0;
01798 
01799        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
01800               return;
01801        }
01802 
01803        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01804 
01805        doc_props = dom_get_doc_props(intern->document);
01806        format = doc_props->formatoutput;
01807 
01808        if (nodep != NULL) {
01809               /* Dump contents of Node */
01810               DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
01811               if (node->doc != docp) {
01812                      php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
01813                      RETURN_FALSE;
01814               }
01815               buf = xmlBufferCreate();
01816               if (!buf) {
01817                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer");
01818                      RETURN_FALSE;
01819               }
01820               if (options & LIBXML_SAVE_NOEMPTYTAG) {
01821                      saveempty = xmlSaveNoEmptyTags;
01822                      xmlSaveNoEmptyTags = 1;
01823               }
01824               xmlNodeDump(buf, docp, node, 0, format);
01825               if (options & LIBXML_SAVE_NOEMPTYTAG) {
01826                      xmlSaveNoEmptyTags = saveempty;
01827               }
01828               mem = (xmlChar*) xmlBufferContent(buf);
01829               if (!mem) {
01830                      xmlBufferFree(buf);
01831                      RETURN_FALSE;
01832               }
01833               RETVAL_STRING(mem, 1);
01834               xmlBufferFree(buf);
01835        } else {
01836               if (options & LIBXML_SAVE_NOEMPTYTAG) {
01837                      saveempty = xmlSaveNoEmptyTags;
01838                      xmlSaveNoEmptyTags = 1;
01839               }
01840               /* Encoding is handled from the encoding property set on the document */
01841               xmlDocDumpFormatMemory(docp, &mem, &size, format);
01842               if (options & LIBXML_SAVE_NOEMPTYTAG) {
01843                      xmlSaveNoEmptyTags = saveempty;
01844               }
01845               if (!size) {
01846                      RETURN_FALSE;
01847               }
01848               RETVAL_STRINGL(mem, size, 1);
01849               xmlFree(mem);
01850        }
01851 }
01852 /* }}} end dom_document_savexml */
01853 
01854 static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur TSRMLS_DC) /* {{{ */
01855 {
01856        xmlNodePtr xincnode;
01857 
01858        xincnode = cur;
01859        cur = cur->next;
01860        xmlUnlinkNode(xincnode);
01861        php_libxml_node_free_resource(xincnode TSRMLS_CC);
01862 
01863        return cur;
01864 }
01865 /* }}} */
01866 
01867 static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) /* {{{ */
01868 {
01869        while(cur) {
01870               if (cur->type == XML_XINCLUDE_START) {
01871                      cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
01872 
01873                      /* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
01874                      while(cur && cur->type != XML_XINCLUDE_END) {
01875                             /* remove xinclude processing nodes from recursive xincludes */
01876                             if (cur->type == XML_ELEMENT_NODE) {
01877                                       php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
01878                             }
01879                             cur = cur->next;
01880                      }
01881 
01882                      if (cur && cur->type == XML_XINCLUDE_END) {
01883                             cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
01884                      }
01885               } else {
01886                      if (cur->type == XML_ELEMENT_NODE) {
01887                             php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
01888                      }
01889                      cur = cur->next;
01890               }
01891        }
01892 }
01893 /* }}} */
01894 
01895 /* {{{ proto int dom_document_xinclude([int options])
01896    Substitutues xincludes in a DomDocument */
01897 PHP_FUNCTION(dom_document_xinclude)
01898 {
01899        zval *id;
01900        xmlDoc *docp;
01901        xmlNodePtr root;
01902        long flags = 0; 
01903        int err;
01904        dom_object *intern;
01905 
01906        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &id, dom_document_class_entry, &flags) == FAILURE) {
01907               return;
01908        }
01909 
01910        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01911 
01912        err = xmlXIncludeProcessFlags(docp, flags);
01913 
01914        /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
01915        are added via xmlXIncludeProcess to mark beginning and ending of xincluded document 
01916        but are not wanted in resulting document - must be done even if err as it could fail after
01917        having processed some xincludes */
01918        root = (xmlNodePtr) docp->children;
01919        while(root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) {
01920               root = root->next;
01921        }
01922        if (root) {
01923               php_dom_remove_xinclude_nodes(root TSRMLS_CC);
01924        }
01925 
01926        if (err) {
01927               RETVAL_LONG(err);
01928        } else {
01929               RETVAL_FALSE;
01930        }
01931     
01932 }
01933 /* }}} */
01934 
01935 /* {{{ proto boolean dom_document_validate();
01936 Since: DOM extended
01937 */
01938 PHP_FUNCTION(dom_document_validate)
01939 {
01940        zval *id;
01941        xmlDoc *docp;
01942        dom_object *intern;
01943        xmlValidCtxt *cvp;
01944 
01945        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_document_class_entry) == FAILURE) {
01946               return;
01947        }
01948 
01949        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01950 
01951        cvp = xmlNewValidCtxt();
01952        
01953        cvp->userData = NULL;
01954        cvp->error    = (xmlValidityErrorFunc) php_libxml_error_handler;
01955        cvp->warning  = (xmlValidityErrorFunc) php_libxml_error_handler;
01956        
01957        if (xmlValidateDocument(cvp, docp)) {
01958               RETVAL_TRUE;
01959        } else {
01960               RETVAL_FALSE;
01961        }
01962        
01963        xmlFreeValidCtxt(cvp);
01964        
01965 }
01966 /* }}} */
01967 
01968 #if defined(LIBXML_SCHEMAS_ENABLED)
01969 static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
01970 {
01971        zval *id;
01972        xmlDoc *docp;
01973        dom_object *intern;
01974        char *source = NULL, *valid_file = NULL;
01975        int source_len = 0;
01976        xmlSchemaParserCtxtPtr  parser;
01977        xmlSchemaPtr            sptr;
01978        xmlSchemaValidCtxtPtr   vptr;
01979        int                     is_valid;
01980        char resolved_path[MAXPATHLEN + 1];
01981 
01982        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
01983               return;
01984        }
01985 
01986        if (source_len == 0) {
01987               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema source");
01988               RETURN_FALSE;
01989        }
01990 
01991        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
01992 
01993        switch (type) {
01994        case DOM_LOAD_FILE:
01995               valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
01996               if (!valid_file) {
01997                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema file source");
01998                      RETURN_FALSE;
01999               }
02000               parser = xmlSchemaNewParserCtxt(valid_file);
02001               break;
02002        case DOM_LOAD_STRING:
02003               parser = xmlSchemaNewMemParserCtxt(source, source_len);
02004               /* If loading from memory, we need to set the base directory for the document 
02005                  but it is not apparent how to do that for schema's */
02006               break;
02007        default:
02008               return;
02009        }
02010 
02011        xmlSchemaSetParserErrors(parser,
02012               (xmlSchemaValidityErrorFunc) php_libxml_error_handler,
02013               (xmlSchemaValidityWarningFunc) php_libxml_error_handler,
02014               parser);
02015        sptr = xmlSchemaParse(parser);
02016        xmlSchemaFreeParserCtxt(parser);
02017        if (!sptr) {
02018               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema");
02019               RETURN_FALSE;
02020        }
02021 
02022        docp = (xmlDocPtr) dom_object_get_node(intern);
02023 
02024        vptr = xmlSchemaNewValidCtxt(sptr);
02025        if (!vptr) {
02026               xmlSchemaFree(sptr);
02027               php_error(E_ERROR, "Invalid Schema Validation Context");
02028               RETURN_FALSE;
02029        }
02030 
02031        xmlSchemaSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
02032        is_valid = xmlSchemaValidateDoc(vptr, docp);
02033        xmlSchemaFree(sptr);
02034        xmlSchemaFreeValidCtxt(vptr);
02035 
02036        if (is_valid == 0) {
02037               RETURN_TRUE;
02038        } else {
02039               RETURN_FALSE;
02040        }
02041 }
02042 /* }}} */
02043 
02044 /* {{{ proto boolean dom_document_schema_validate_file(string filename); */
02045 PHP_FUNCTION(dom_document_schema_validate_file)
02046 {
02047        _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
02048 }
02049 /* }}} end dom_document_schema_validate_file */
02050 
02051 /* {{{ proto boolean dom_document_schema_validate(string source); */
02052 PHP_FUNCTION(dom_document_schema_validate_xml)
02053 {
02054        _dom_document_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
02055 }
02056 /* }}} end dom_document_schema_validate */
02057 
02058 static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
02059 {
02060        zval *id;
02061        xmlDoc *docp;
02062        dom_object *intern;
02063        char *source = NULL, *valid_file = NULL;
02064        int source_len = 0;
02065        xmlRelaxNGParserCtxtPtr parser;
02066        xmlRelaxNGPtr           sptr;
02067        xmlRelaxNGValidCtxtPtr  vptr;
02068        int                     is_valid;
02069        char resolved_path[MAXPATHLEN + 1];
02070 
02071        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &source, &source_len) == FAILURE) {
02072               return;
02073        }
02074 
02075        if (source_len == 0) {
02076               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Schema source");
02077               RETURN_FALSE;
02078        }
02079 
02080        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
02081 
02082        switch (type) {
02083        case DOM_LOAD_FILE:
02084               valid_file = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN  TSRMLS_CC);
02085               if (!valid_file) {
02086                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid RelaxNG file source");
02087                      RETURN_FALSE;
02088               }
02089               parser = xmlRelaxNGNewParserCtxt(valid_file);
02090               break;
02091        case DOM_LOAD_STRING:
02092               parser = xmlRelaxNGNewMemParserCtxt(source, source_len);
02093               /* If loading from memory, we need to set the base directory for the document 
02094                  but it is not apparent how to do that for schema's */
02095               break;
02096        default:
02097               return;
02098        }
02099 
02100        xmlRelaxNGSetParserErrors(parser,
02101               (xmlRelaxNGValidityErrorFunc) php_libxml_error_handler,
02102               (xmlRelaxNGValidityWarningFunc) php_libxml_error_handler,
02103               parser);
02104        sptr = xmlRelaxNGParse(parser);
02105        xmlRelaxNGFreeParserCtxt(parser);
02106        if (!sptr) {
02107               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid RelaxNG");
02108               RETURN_FALSE;
02109        }
02110 
02111        docp = (xmlDocPtr) dom_object_get_node(intern);
02112 
02113        vptr = xmlRelaxNGNewValidCtxt(sptr);
02114        if (!vptr) {
02115               xmlRelaxNGFree(sptr);
02116               php_error(E_ERROR, "Invalid RelaxNG Validation Context");
02117               RETURN_FALSE;
02118        }
02119 
02120        xmlRelaxNGSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr);
02121        is_valid = xmlRelaxNGValidateDoc(vptr, docp);
02122        xmlRelaxNGFree(sptr);
02123        xmlRelaxNGFreeValidCtxt(vptr);
02124 
02125        if (is_valid == 0) {
02126               RETURN_TRUE;
02127        } else {
02128               RETURN_FALSE;
02129        }
02130 }
02131 /* }}} */
02132 
02133 /* {{{ proto boolean dom_document_relaxNG_validate_file(string filename); */
02134 PHP_FUNCTION(dom_document_relaxNG_validate_file)
02135 {
02136        _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
02137 }
02138 /* }}} end dom_document_relaxNG_validate_file */
02139 
02140 /* {{{ proto boolean dom_document_relaxNG_validate_xml(string source); */
02141 PHP_FUNCTION(dom_document_relaxNG_validate_xml)
02142 {
02143        _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
02144 }
02145 /* }}} end dom_document_relaxNG_validate_xml */
02146 
02147 #endif
02148 
02149 #if defined(LIBXML_HTML_ENABLED)
02150 
02151 static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
02152 {
02153        zval *id, *rv = NULL;
02154        xmlDoc *docp = NULL, *newdoc;
02155        dom_object *intern;
02156        dom_doc_propsptr doc_prop;
02157        char *source;
02158        int source_len, refcount, ret;
02159        htmlParserCtxtPtr ctxt;
02160        
02161        id = getThis();
02162 
02163        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &source_len) == FAILURE) {
02164               return;
02165        }
02166 
02167        if (!source_len) {
02168               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string supplied as input");
02169               RETURN_FALSE;
02170        }
02171 
02172        if (mode == DOM_LOAD_FILE) {
02173               ctxt = htmlCreateFileParserCtxt(source, NULL);
02174        } else {
02175               source_len = xmlStrlen(source);
02176               ctxt = htmlCreateMemoryParserCtxt(source, source_len);
02177        }
02178 
02179        if (!ctxt) {
02180               RETURN_FALSE;
02181        }
02182 
02183        ctxt->vctxt.error = php_libxml_ctx_error;
02184        ctxt->vctxt.warning = php_libxml_ctx_warning;
02185        if (ctxt->sax != NULL) {
02186               ctxt->sax->error = php_libxml_ctx_error;
02187               ctxt->sax->warning = php_libxml_ctx_warning;
02188        }
02189        htmlParseDocument(ctxt);
02190        newdoc = ctxt->myDoc;
02191        htmlFreeParserCtxt(ctxt);
02192        
02193        if (!newdoc)
02194               RETURN_FALSE;
02195 
02196        if (id != NULL && instanceof_function(Z_OBJCE_P(id), dom_document_class_entry TSRMLS_CC)) {
02197               intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
02198               if (intern != NULL) {
02199                      docp = (xmlDocPtr) dom_object_get_node(intern);
02200                      doc_prop = NULL;
02201                      if (docp != NULL) {
02202                             php_libxml_decrement_node_ptr((php_libxml_node_object *) intern TSRMLS_CC);
02203                             doc_prop = intern->document->doc_props;
02204                             intern->document->doc_props = NULL;
02205                             refcount = php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
02206                             if (refcount != 0) {
02207                                    docp->_private = NULL;
02208                             }
02209                      }
02210                      intern->document = NULL;
02211                      if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc TSRMLS_CC) == -1) {
02212                             RETURN_FALSE;
02213                      }
02214                      intern->document->doc_props = doc_prop;
02215               }
02216 
02217               php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern TSRMLS_CC);
02218 
02219               RETURN_TRUE;
02220        } else {
02221               DOM_RET_OBJ(rv, (xmlNodePtr) newdoc, &ret, NULL);
02222        }
02223 }
02224 /* }}} */
02225 
02226 /* {{{ proto DOMNode dom_document_load_html_file(string source);
02227 Since: DOM extended
02228 */
02229 PHP_METHOD(domdocument, loadHTMLFile)
02230 {
02231        dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
02232 }
02233 /* }}} end dom_document_load_html_file */
02234 
02235 /* {{{ proto DOMNode dom_document_load_html(string source);
02236 Since: DOM extended
02237 */
02238 PHP_METHOD(domdocument, loadHTML)
02239 {
02240        dom_load_html(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
02241 }
02242 /* }}} end dom_document_load_html */
02243 
02244 /* {{{ proto int dom_document_save_html_file(string file);
02245 Convenience method to save to file as html
02246 */
02247 PHP_FUNCTION(dom_document_save_html_file)
02248 {
02249        zval *id;
02250        xmlDoc *docp;
02251        int file_len, bytes, format;
02252        dom_object *intern;
02253        dom_doc_propsptr doc_props;
02254        char *file;
02255        const char *encoding;
02256 
02257        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_document_class_entry, &file, &file_len) == FAILURE) {
02258               return;
02259        }
02260 
02261        if (file_len == 0) {
02262               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Filename");
02263               RETURN_FALSE;
02264        }
02265 
02266        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
02267 
02268 
02269        encoding = (const char *) htmlGetMetaEncoding(docp);
02270 
02271        doc_props = dom_get_doc_props(intern->document);
02272        format = doc_props->formatoutput;
02273        bytes = htmlSaveFileFormat(file, docp, encoding, format);
02274 
02275        if (bytes == -1) {
02276               RETURN_FALSE;
02277        }
02278        RETURN_LONG(bytes);
02279 }
02280 /* }}} end dom_document_save_html_file */
02281 
02282 /* {{{ proto string dom_document_save_html();
02283 Convenience method to output as html
02284 */
02285 PHP_FUNCTION(dom_document_save_html)
02286 {
02287        zval *id, *nodep = NULL;
02288        xmlDoc *docp;
02289        xmlNode *node;
02290        xmlBufferPtr buf;
02291        dom_object *intern, *nodeobj;
02292        xmlChar *mem = NULL;
02293        int size, format;
02294        dom_doc_propsptr doc_props;
02295 
02296        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
02297               "O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry)
02298               == FAILURE) {
02299               return;
02300        }
02301 
02302        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
02303 
02304        doc_props = dom_get_doc_props(intern->document);
02305        format = doc_props->formatoutput;
02306 
02307        if (nodep != NULL) {
02308               /* Dump contents of Node */
02309               DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
02310               if (node->doc != docp) {
02311                      php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
02312                      RETURN_FALSE;
02313               }
02314               
02315               buf = xmlBufferCreate();
02316               if (!buf) {
02317                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch buffer");
02318                      RETURN_FALSE;
02319               }
02320               
02321               size = htmlNodeDump(buf, docp, node);
02322               if (size >= 0) {
02323                      mem = (xmlChar*) xmlBufferContent(buf);
02324                      if (!mem) {
02325                             RETVAL_FALSE;
02326                      } else {
02327                             RETVAL_STRINGL((const char*) mem, size, 1);
02328                      }
02329               } else {
02330                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error dumping HTML node");
02331                      RETVAL_FALSE;
02332               }
02333               xmlBufferFree(buf);
02334        } else {
02335 #if LIBXML_VERSION >= 20623
02336               htmlDocDumpMemoryFormat(docp, &mem, &size, format);
02337 #else
02338               htmlDocDumpMemory(docp, &mem, &size);
02339 #endif
02340               if (!size) {
02341                      RETVAL_FALSE;
02342               } else {
02343                      RETVAL_STRINGL((const char*) mem, size, 1);
02344               }
02345               if (mem)
02346                      xmlFree(mem);
02347        }
02348 
02349 }
02350 /* }}} end dom_document_save_html */
02351 
02352 #endif  /* defined(LIBXML_HTML_ENABLED) */
02353 
02354 /* {{{ proto boolean DOMDocument::registerNodeClass(string baseclass, string extendedclass);
02355    Register extended class used to create base node type */
02356 PHP_METHOD(domdocument, registerNodeClass)
02357 {
02358        zval *id;
02359        xmlDoc *docp;
02360        char *baseclass = NULL, *extendedclass = NULL;
02361        int baseclass_len = 0, extendedclass_len = 0;
02362        zend_class_entry *basece = NULL, *ce = NULL;
02363        dom_object *intern;
02364 
02365        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss!", &id, dom_document_class_entry, &baseclass, &baseclass_len, &extendedclass, &extendedclass_len) == FAILURE) {
02366               return;
02367        }
02368 
02369        if (baseclass_len) {
02370               zend_class_entry **pce;
02371               if (zend_lookup_class(baseclass, baseclass_len, &pce TSRMLS_CC) == FAILURE) {
02372                      php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", baseclass);
02373                      return;
02374               }
02375               basece = *pce;
02376        }
02377 
02378        if (basece == NULL || ! instanceof_function(basece, dom_node_class_entry TSRMLS_CC)) {
02379               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not derived from DOMNode.", baseclass);
02380               return;
02381        }
02382 
02383        if (extendedclass_len) {
02384               zend_class_entry **pce;
02385               if (zend_lookup_class(extendedclass, extendedclass_len, &pce TSRMLS_CC) == FAILURE) {
02386                      php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s does not exist", extendedclass);
02387               }
02388               ce = *pce;
02389        }
02390 
02391        if (ce == NULL || instanceof_function(ce, basece TSRMLS_CC)) {
02392 
02393               DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
02394 
02395               if (dom_set_doc_classmap(intern->document, basece, ce TSRMLS_CC) == FAILURE) {
02396                      php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be registered.", extendedclass);
02397               }
02398               RETURN_TRUE;
02399        } else {
02400               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not derived from %s.", extendedclass, baseclass);
02401        }
02402 
02403        RETURN_FALSE;
02404 }
02405 /* }}} */
02406 
02407 #endif  /* HAVE_LIBXML && HAVE_DOM */
02408 
02409 /*
02410  * Local variables:
02411  * tab-width: 4
02412  * c-basic-offset: 4
02413  * End:
02414  * vim600: noet sw=4 ts=4 fdm=marker
02415  * vim<600: noet sw=4 ts=4
02416  */