cvs: php4 /ext/domxml php_domxml.c php_domxml.h

From: Date: Thu, 16 May 2002 21:59:28 +0000
Subject: cvs: php4 /ext/domxml php_domxml.c php_domxml.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11965@lists.php.net to get a copy of this message
chregu Thu May 16 17:59:28 2002 EDT Modified files: /php4/ext/domxml php_domxml.c php_domxml.h Log: - replaced domxml_doc_document_element implementation do use libxml2 method - renamed domxml_add_root to domxml_doc_add_root (and added alias for BC) - aliased $doc->get_root to domxml_document_element @ - added domxml_doc_set_root to change the root node (Lukas Schroeder) Index: php4/ext/domxml/php_domxml.c diff -u php4/ext/domxml/php_domxml.c:1.150 php4/ext/domxml/php_domxml.c:1.151 --- php4/ext/domxml/php_domxml.c:1.150 Fri May 10 10:59:14 2002 +++ php4/ext/domxml/php_domxml.c Thu May 16 17:59:24 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_domxml.c,v 1.150 2002/05/10 14:59:14 chregu Exp $ */ +/* $Id: php_domxml.c,v 1.151 2002/05/16 21:59:24 chregu Exp $ */ /* TODO * - Support Notation Nodes @@ -198,10 +198,12 @@ PHP_FE(html_doc, NULL) PHP_FE(html_doc_file, NULL) #endif - PHP_FE(domxml_xmltree, NULL) - PHP_FALIAS(xmltree, domxml_xmltree, NULL) - PHP_FE(domxml_substitute_entities_default, NULL) - PHP_FE(domxml_add_root, NULL) + PHP_FE(domxml_xmltree, NULL) + PHP_FALIAS(xmltree, domxml_xmltree, NULL) + PHP_FE(domxml_substitute_entities_default, NULL) + PHP_FE(domxml_doc_document_element, NULL) + PHP_FE(domxml_doc_add_root, NULL) + PHP_FE(domxml_doc_set_root, NULL) PHP_FE(domxml_dump_mem, NULL) PHP_FE(domxml_dump_mem_file, NULL) PHP_FE(domxml_dump_node, NULL) @@ -219,7 +221,7 @@ PHP_FE(domxml_node_set_content, NULL) PHP_FE(domxml_node_get_content, NULL) PHP_FE(domxml_new_xmldoc, NULL) - PHP_FALIAS(domxml_new_doc, domxml_new_xmldoc, NULL) + PHP_FALIAS(domxml_new_doc, domxml_new_xmldoc, NULL) PHP_FE(domxml_parser, NULL) PHP_FE(domxml_parser_add_chunk, NULL) PHP_FE(domxml_parser_end, NULL) @@ -243,6 +245,8 @@ PHP_FE(domxml_xslt_process, NULL) #endif + PHP_FALIAS(domxml_add_root, domxml_doc_add_root, NULL) + PHP_FALIAS(domxml_doc_get_root, domxml_doc_document_element, NULL) PHP_FALIAS(domxml_root, domxml_doc_document_element, NULL) PHP_FALIAS(domxml_attributes, domxml_node_attributes, NULL) PHP_FALIAS(domxml_get_attribute, domxml_elem_get_attribute, NULL) @@ -276,15 +280,17 @@ /* Everything below this comment is none DOM compliant */ /* children is deprecated because it is inherited from DomNode */ /* PHP_FALIAS(children, domxml_node_children, NULL) */ + PHP_FALIAS(add_root, domxml_doc_add_root, NULL) + PHP_FALIAS(set_root, domxml_doc_set_root, NULL) + PHP_FALIAS(get_root, domxml_doc_document_element, NULL) PHP_FALIAS(root, domxml_doc_document_element, NULL) - PHP_FALIAS(add_root, domxml_add_root, NULL) PHP_FALIAS(imported_node, domxml_doc_imported_node, NULL) PHP_FALIAS(dtd, domxml_intdtd, NULL) PHP_FALIAS(ids, domxml_doc_ids, NULL) PHP_FALIAS(dumpmem, domxml_dump_mem, NULL) PHP_FALIAS(dump_mem, domxml_dump_mem, NULL) PHP_FALIAS(dump_mem_file, domxml_dump_mem_file, NULL) - PHP_FALIAS(dump_file, domxml_dump_mem_file, NULL) + PHP_FALIAS(dump_file, domxml_dump_mem_file, NULL) #if defined(LIBXML_HTML_ENABLED) PHP_FALIAS(html_dump_mem, domxml_html_dump_mem, NULL) #endif @@ -455,7 +461,7 @@ PHP_RINIT(domxml), NULL, PHP_MINFO(domxml), - "20020510", //Extension versionnumber + "20020516", //Extension versionnumber STANDARD_MODULE_PROPERTIES }; @@ -2887,38 +2893,23 @@ } /* }}} */ -/* {{{ proto array domxml_doc_document_element(void) +/* {{{ proto object domxml_doc_document_element(int domnode) Returns root node of document */ PHP_FUNCTION(domxml_doc_document_element) { - zval *id; + zval *id, *rv; xmlDoc *docp; - xmlNode *node; + xmlNode *root; int ret; - id = getThis(); - - if (!id) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &id) == FAILURE) { - return; - } - } - - DOMXML_GET_OBJ(docp, id, le_domxmldocp); + DOMXML_PARAM_NONE(docp, id, le_domxmldocp); - node = docp->children; - if (!node) { + root = xmlDocGetRootElement(docp); + if (!root) { RETURN_FALSE; } - while (node) { - if (Z_TYPE_P(node) == XML_ELEMENT_NODE) { - zval *rv; - DOMXML_RET_OBJ(rv, node, &ret); - return; - } - node = node->next; - } + DOMXML_RET_OBJ(rv, root, &ret); } /* }}} */ @@ -3514,9 +3505,9 @@ } /* }}} */ -/* {{{ proto object domxml_add_root(string name) +/* {{{ proto object domxml_doc_add_root(string name) Adds root node to document */ -PHP_FUNCTION(domxml_add_root) +PHP_FUNCTION(domxml_doc_add_root) { zval *id, *rv; xmlDoc *docp; @@ -3534,6 +3525,27 @@ xmlDocSetRootElement(docp, nodep); DOMXML_RET_OBJ(rv, nodep, &ret); +} +/* }}} */ + +/* {{{ proto bool domxml_set_root(int domnode) + Sets root node of document */ +PHP_FUNCTION(domxml_doc_set_root) +{ + zval *id, *rv, *node; + xmlDoc *docp; + xmlNode *root; + + DOMXML_PARAM_TWO(docp, id, le_domxmldocp, "o", &node, &rv); + DOMXML_GET_OBJ(root, node, le_domxmlnodep); + + if (!root) { + RETURN_FALSE; + } + + xmlDocSetRootElement(docp, root); + + RETURN_TRUE; } /* }}} */ Index: php4/ext/domxml/php_domxml.h diff -u php4/ext/domxml/php_domxml.h:1.52 php4/ext/domxml/php_domxml.h:1.53 --- php4/ext/domxml/php_domxml.h:1.52 Fri May 3 09:53:46 2002 +++ php4/ext/domxml/php_domxml.h Thu May 16 17:59:26 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_domxml.h,v 1.52 2002/05/03 13:53:46 chregu Exp $ */ +/* $Id: php_domxml.h,v 1.53 2002/05/16 21:59:26 chregu Exp $ */ #ifndef PHP_DOMXML_H #define PHP_DOMXML_H @@ -68,7 +68,6 @@ /* Class Document methods */ PHP_FUNCTION(domxml_doc_doctype); PHP_FUNCTION(domxml_doc_implementation); -PHP_FUNCTION(domxml_doc_document_element); PHP_FUNCTION(domxml_doc_create_element); PHP_FUNCTION(domxml_doc_create_text_node); PHP_FUNCTION(domxml_doc_create_comment); @@ -77,7 +76,9 @@ PHP_FUNCTION(domxml_doc_create_cdata_section); PHP_FUNCTION(domxml_doc_create_entity_reference); PHP_FUNCTION(domxml_doc_imported_node); -PHP_FUNCTION(domxml_add_root); +PHP_FUNCTION(domxml_doc_add_root); +PHP_FUNCTION(domxml_doc_document_element); +PHP_FUNCTION(domxml_doc_set_root); PHP_FUNCTION(domxml_intdtd); PHP_FUNCTION(domxml_doc_ids); PHP_FUNCTION(domxml_dump_mem);

« previous php.cvs (#11965) next »