cvs: php4 /ext/domxml php_domxml.c
| From: | Uwe Steinmann | Date: | Tue, 23 Apr 2002 13:24:26 +0000 |
| Subject: | cvs: php4 /ext/domxml php_domxml.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11343@lists.php.net to get a copy of this message | ||
steinm Tue Apr 23 09:24:26 2002 EDT
Modified files:
/php4/ext/domxml php_domxml.c
Log:
- replace_child() will not add a child twice
- domxml_open_mem() drops old optional parameter to switch between reading
from a string or a file.
- new optional parameter for domxml_open_mem() which set the mode how the
document shall be parsed
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.142 php4/ext/domxml/php_domxml.c:1.143
--- php4/ext/domxml/php_domxml.c:1.142 Tue Apr 23 02:05:38 2002
+++ php4/ext/domxml/php_domxml.c Tue Apr 23 09:24:25 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.142 2002/04/23 06:05:38 steinm Exp $ */
+/* $Id: php_domxml.c,v 1.143 2002/04/23 13:24:25 steinm Exp $ */
/* TODO
* - Support Notation Nodes
@@ -129,6 +129,11 @@
} \
DOMXML_GET_OBJ(ret, zval, le);
+#define DOMXML_LOAD_PARSING 0
+#define DOMXML_LOAD_VALIDATING 1
+#define DOMXML_LOAD_RECOVERING 2
+#define DOMXML_LOAD_SUBSTITUTE_ENTITIES 4
+#define DOMXML_LOAD_COMPLETE_ATTRS 8
static int le_domxmldocp;
static int le_domxmldoctypep;
@@ -1366,6 +1371,12 @@
REGISTER_LONG_CONSTANT("XPATH_USERS", XPATH_USERS, CONST_CS | CONST_PERSISTENT);
#endif
+ REGISTER_LONG_CONSTANT("DOMXML_LOAD_PARSING", DOMXML_LOAD_PARSING, CONST_CS |
CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOMXML_LOAD_VALIDATING", DOMXML_LOAD_VALIDATING, CONST_CS |
CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOMXML_LOAD_RECOVERING", DOMXML_LOAD_RECOVERING, CONST_CS |
CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOMXML_LOAD_SUBSTITUTE_ENTITIES", DOMXML_LOAD_SUBSTITUTE_ENTITIES, CONST_CS
| CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DOMXML_LOAD_COMPLETE_ATTRS",DOMXML_LOAD_COMPLETE_ATTRS, CONST_CS
| CONST_PERSISTENT);
+
xmlSetGenericErrorFunc(xmlGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
#if HAVE_DOMXSLT
xsltSetGenericErrorFunc(xsltGenericErrorContext, (xmlGenericErrorFunc)domxml_error);
@@ -2182,6 +2193,7 @@
{
zval *id, *newnode, *oldnode;
xmlNodePtr children, newchild, oldchild, nodep;
+ int foundoldchild = 0, foundnewchild = 0;
int ret;
DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlnodep);
@@ -2198,17 +2210,37 @@
RETURN_FALSE;
}
+ /* check for the old child and wether the new child is already a child */
while (children) {
if (children == oldchild) {
- zval *rv;
- xmlNodePtr node;
- node = xmlReplaceNode(oldchild, newchild);
- DOMXML_RET_OBJ(rv, oldchild, &ret);
- return;
+ foundoldchild = 1;
+ }
+ if(children == newchild) {
+ foundnewchild = 1;
}
children = children->next;
}
- RETURN_FALSE
+ /* if the child to replace is existent and the new child isn't already
+ * a child, then do the replacement
+ */
+ if(foundoldchild && !foundnewchild) {
+ zval *rv;
+ xmlNodePtr node;
+ node = xmlReplaceNode(oldchild, newchild);
+ DOMXML_RET_OBJ(rv, oldchild, &ret);
+ return;
+ }
+ /* If the new child is already a child, then DOM requires to delete
+ * the old one first, but this makes no sense here, since the old and
+ * the new node are identical.
+ */
+ if(foundnewchild) {
+ zval *rv;
+ DOMXML_RET_OBJ(rv, newchild, &ret);
+ return;
+ } else {
+ RETURN_FALSE;
+ }
}
/* }}} */
@@ -2669,9 +2701,6 @@
xmlHashTable *ids = NULL;
int retnode;
- int name_len;
- char *str, *name;
-
id = getThis();
DOMXML_GET_OBJ(docp, id, le_domxmldocp);
@@ -3289,7 +3318,7 @@
}
/* }}} */
-/* {{{ proto object xmldoc(string xmldoc [, bool from_file])
+/* {{{ proto object xmldoc(string xmldoc[, int mode])
Creates DOM object of XML document */
PHP_FUNCTION(xmldoc)
{
@@ -3298,21 +3327,42 @@
int ret;
char *buffer;
int buffer_len;
- zend_bool from_file = 0;
- xmlDtdPtr dtd;
+ int mode = 0, prevSubstValue;
+ int oldvalue = xmlDoValidityCheckingDefaultValue;
+/* xmlDtdPtr dtd; */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &buffer,
&buffer_len, &from_file) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &buffer,
&buffer_len, &mode) == FAILURE) {
return;
}
/* Either of the following line force validation */
/* xmlLoadExtDtdDefaultValue = XML_DETECT_IDS; */
/* xmlDoValidityCheckingDefaultValue = 1; */
- if (from_file) {
- docp = xmlParseFile(buffer);
- } else {
- docp = xmlParseDoc(buffer);
+ if(mode & DOMXML_LOAD_SUBSTITUTE_ENTITIES)
+ prevSubstValue = xmlSubstituteEntitiesDefault (1);
+ else
+ prevSubstValue = xmlSubstituteEntitiesDefault (0);
+
+ if(mode & DOMXML_LOAD_COMPLETE_ATTRS)
+ xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
+
+ switch (mode & (DOMXML_LOAD_PARSING | DOMXML_LOAD_VALIDATING | DOMXML_LOAD_RECOVERING)) {
+ case DOMXML_LOAD_PARSING:
+ xmlDoValidityCheckingDefaultValue = 0;
+ docp = xmlParseDoc(buffer);
+ break;
+ case DOMXML_LOAD_VALIDATING:
+ xmlDoValidityCheckingDefaultValue = 1;
+ docp = xmlParseDoc(buffer);
+ break;
+ case DOMXML_LOAD_RECOVERING:
+ xmlDoValidityCheckingDefaultValue = 0;
+ docp = xmlRecoverDoc(buffer);
+ break;
}
+ xmlSubstituteEntitiesDefault (prevSubstValue);
+ xmlDoValidityCheckingDefaultValue = oldvalue;
+
if (!docp)
RETURN_FALSE;