Rob Richards wrote: > From: Christian Stocker > >> > $node->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:b", >> > "http://www.somedomain.de/"); >> > > >> IMHO, that would be very confusing. >> >> I liked the idea by vivian with a third optional namespaceURI argument >> for the element object, so that at least you can use your own extended >> classes for that. >> >> And maybe we still need a ->setNamespaceURI method, even if W3C didnt >> think of that ;) > > After thinking about it some more I started to think about it the same > way. One can always then use $node->prefix = "xyz" to set the prefix (if > needed) for the initial namespace delcaration. > It probably has to wait until 5.1 though since its so close to the > release. > > Rob
first of all, thanks for your interests... i tried my self in extending your code - i'm really no C programmer, just copy&pasted it (poor to say that, sorry:), but it seems to work. i now can use the following syntax to set the namespaceUri of a node: <?php $element = new DomElement("tagname", "value", "http://namespaceUri"); // or $element = new DomElement("pref:tagname", "value", "http://namespaceUri"); // works as well ?> here is the diff output: --- ./element_original.c 2004-02-15 15:08:52.000000000 +0100 +++ ./element.c 2004-02-17 20:53:35.000000000 +0100 @@ -64,11 +64,14 @@ zval *id; xmlNodePtr nodep = NULL, oldnode = NULL; + xmlNsPtr nsptr = NULL; dom_object *intern; - char *name, *value = NULL; - int name_len, value_len = 0; + char *name, *value = NULL, *uri = NULL; + char *localname = NULL, *prefix = NULL; + int name_len, value_len = 0, uri_len = 0; + int errorcode; - if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_element_class_entry, &name, &name_len, &value, &value_len) == FAILURE) { + if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|ss", &id, dom_element_class_entry, &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) { return; } @@ -77,15 +80,49 @@ RETURN_FALSE; } - nodep = xmlNewNode(NULL, (xmlChar *) name); + // + + errorcode = dom_check_qname(name, &localname, &prefix, uri_len, name_len); + + if (errorcode == 0) { + nodep = xmlNewNode(NULL, (xmlChar *) localname); + + if (!nodep) + RETURN_FALSE; + + if (value_len > 0) { + xmlNodeSetContentLen(nodep, value, value_len); + } + // nodep = xmlNewDocNode (docp, NULL, localname, NULL); + if (nodep != NULL && uri != NULL) { + nsptr = xmlSearchNsByHref (nodep->doc, nodep, uri); + if (nsptr == NULL) { + nsptr = dom_get_ns(nodep, uri, &errorcode, prefix); + } + xmlSetNs(nodep, nsptr); + } + } - if (!nodep) + xmlFree(localname); + if (prefix != NULL) { + xmlFree(prefix); + } + + if (errorcode != 0) { + if (nodep != NULL) { + xmlFreeNode(nodep); + } + php_dom_throw_error(errorcode, dom_get_strict_error(intern->document) TSRMLS_CC); RETURN_FALSE; + } - if (value_len > 0) { - xmlNodeSetContentLen(nodep, value, value_len); + if (nodep == NULL) { + RETURN_FALSE; } + + nodep->ns = nsptr; + // intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC); if (intern != NULL) { oldnode = (xmlNodePtr)intern->ptr; @@ -97,8 +134,8 @@ } /* }}} end dom_element_element */ -/* {{{ proto tagName string -readonly=yes +/* {{{ proto tagName string +readonly=yes URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226 DOM3-Core.html#core-ID-104682815 Since: */ as you said it's close to the release and i won't bring you into trouble, but maybe you can take a short time to look if i had made some heavy errors... MANY MANY THANKS in advance, best regards vivian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php