cvs: php4 /ext/domxml php_domxml.c php_domxml.h
| From: | Christian Stocker | Date: | Wed, 14 Aug 2002 14:23:44 +0000 |
| Subject: | cvs: php4 /ext/domxml php_domxml.c php_domxml.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-13347@lists.php.net to get a copy of this message | ||
chregu Wed Aug 14 10:23:44 2002 EDT
Modified files:
/php4/ext/domxml php_domxml.c php_domxml.h
Log:
@ - Added some namespace support with DomNode->add_namespace(uri, prefix)
@ and DomDocument->create_element_ns(uri, nodename) (chregu)
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.188 php4/ext/domxml/php_domxml.c:1.189
--- php4/ext/domxml/php_domxml.c:1.188 Wed Aug 14 05:07:34 2002
+++ php4/ext/domxml/php_domxml.c Wed Aug 14 10:23:44 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.188 2002/08/14 09:07:34 chregu Exp $ */
+/* $Id: php_domxml.c,v 1.189 2002/08/14 14:23:44 chregu Exp $ */
/* TODO
* - Support Notation Nodes
@@ -232,6 +232,7 @@
PHP_FE(domxml_node_unlink_node, NULL)
PHP_FE(domxml_node_set_content, NULL)
PHP_FE(domxml_node_get_content, NULL)
+ PHP_FE(domxml_node_add_namespace, NULL)
PHP_FE(domxml_new_xmldoc, NULL)
PHP_FALIAS(domxml_new_doc, domxml_new_xmldoc, NULL)
PHP_FE(domxml_parser, NULL)
@@ -295,6 +296,7 @@
PHP_FALIAS(implementation, domxml_doc_implementation, NULL)
PHP_FALIAS(document_element, domxml_doc_document_element, NULL)
PHP_FALIAS(create_element, domxml_doc_create_element, NULL)
+ PHP_FALIAS(create_element_ns, domxml_doc_create_element_ns, NULL)
PHP_FALIAS(create_text_node, domxml_doc_create_text_node, NULL)
PHP_FALIAS(create_comment, domxml_doc_create_comment, NULL)
PHP_FALIAS(create_attribute, domxml_doc_create_attribute, NULL)
@@ -392,6 +394,7 @@
PHP_FALIAS(namespace_uri, domxml_node_namespace_uri, NULL)
PHP_FALIAS(clone_node, domxml_clone_node, NULL)
/* Non DOM functions start here */
+ PHP_FALIAS(add_namespace, domxml_node_add_namespace, NULL)
PHP_FALIAS(add_child, domxml_node_append_child, NULL)
PHP_FALIAS(append_sibling, domxml_node_append_sibling, NULL)
PHP_FALIAS(node, domxml_node, NULL)
@@ -2374,6 +2377,11 @@
RETURN_FALSE;
}
+ /* copy namespace if one is there */
+ if (child->ns) {
+ new_child->ns = child->ns;
+ }
+
/* FIXME reverted xmlAddChildList; crashes
* Uwe: must have been a temporary problem. It works for me with both
* xmlAddChildList and xmlAddChild
@@ -3282,6 +3290,69 @@
} else {
DOMXML_RET_OBJ(rv, node, &ret);
}
+}
+/* }}} */
+
+/* {{{ proto object domxml_doc_create_element_ns(string uri, string name)
+ Creates new element node with a namespace*/
+PHP_FUNCTION(domxml_doc_create_element_ns)
+{
+ zval *id, *rv = NULL;
+ xmlNode *node;
+ xmlNs *nsptr;
+ xmlDocPtr docp = NULL;
+ int ret, name_len, uri_len;
+ char *name, *uri;
+
+ DOMXML_PARAM_FOUR(docp, id, le_domxmldocp, "ss", &uri, &uri_len, &name,
&name_len);
+
+ nsptr = xmlSearchNsByHref(docp, xmlDocGetRootElement(docp), (xmlChar*) uri);
+ node = xmlNewNode(nsptr, name);
+
+ if (!node) {
+ RETURN_FALSE;
+ }
+ /* if no namespace with the same uri was found, we have to create a new one.
+ I do this here with a + the adress of the node. this is not very sophisticated,
+ therefore if someone has a better idea in creating unique prefixes, here's your
+ chance (a0,a1, etc would be good enough, this is the way mozilla does it). I'm
+ to lazy right now to think of a better solution... */
+
+ if (nsptr == NULL) {
+ char prefix[20];
+ sprintf(prefix, "a%d",node);
+ nsptr = xmlNewNs(node, uri, prefix);
+ xmlSetNs(node, nsptr);
+ }
+
+ node->doc = docp;
+
+ if(DOMXML_IS_TYPE(getThis(), domxmlelement_class_entry)) {
+ DOMXML_DOMOBJ_NEW(getThis(), node, &ret);
+ } else {
+ DOMXML_RET_OBJ(rv, node, &ret);
+ }
+}
+/* }}} */
+
+/* {{{ proto object domxml_node_add_namespace(string uri, string prefix)
+ Adds a namespace declaration to a node */
+PHP_FUNCTION(domxml_node_add_namespace)
+{
+ zval *id;
+ xmlNode *nodep;
+ xmlNs *nsptr;
+ int prefix_len, uri_len;
+ char *prefix, *uri;
+
+ DOMXML_PARAM_FOUR(nodep, id, le_domxmldocp, "ss", &uri, &uri_len, &prefix,
&prefix_len);
+
+ if (NULL == (nsptr = xmlNewNs(nodep,uri,prefix))) {
+ RETURN_FALSE;
+ } else {
+ RETURN_TRUE;
+ }
+
}
/* }}} */
Index: php4/ext/domxml/php_domxml.h
diff -u php4/ext/domxml/php_domxml.h:1.66 php4/ext/domxml/php_domxml.h:1.67
--- php4/ext/domxml/php_domxml.h:1.66 Wed Aug 14 05:20:19 2002
+++ php4/ext/domxml/php_domxml.h Wed Aug 14 10:23:44 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.h,v 1.66 2002/08/14 09:20:19 chregu Exp $ */
+/* $Id: php_domxml.h,v 1.67 2002/08/14 14:23:44 chregu Exp $ */
#ifndef PHP_DOMXML_H
#define PHP_DOMXML_H
@@ -89,6 +89,7 @@
PHP_FUNCTION(domxml_doc_doctype);
PHP_FUNCTION(domxml_doc_implementation);
PHP_FUNCTION(domxml_doc_create_element);
+PHP_FUNCTION(domxml_doc_create_element_ns);
PHP_FUNCTION(domxml_doc_create_text_node);
PHP_FUNCTION(domxml_doc_create_comment);
PHP_FUNCTION(domxml_doc_create_processing_instruction);
@@ -140,6 +141,7 @@
PHP_FUNCTION(domxml_node_parent);
PHP_FUNCTION(domxml_node_prefix);
PHP_FUNCTION(domxml_node_namespace_uri);
+PHP_FUNCTION(domxml_node_add_namespace);
PHP_FUNCTION(domxml_node);
PHP_FUNCTION(domxml_clone_node);
PHP_FUNCTION(domxml_node_unlink_node);