summaryrefslogtreecommitdiff
path: root/ext/dom/domimplementation.c
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2003-07-27 17:57:06 (GMT)
committerRob Richards <rrichards@php.net>2003-07-27 17:57:06 (GMT)
commit43bc2f0b6dcb1af71b2a7770b0c6eb98617c4a89 (patch)
tree7e448e9ef526a841ab0f1db017a233c3c6028030 /ext/dom/domimplementation.c
parentb156ac970315428dbbd817af8828b51bd0e273ce (diff)
downloadphp-43bc2f0b6dcb1af71b2a7770b0c6eb98617c4a89.tar.gz
reworking xml namespace support
add node lookupNamespaceURI and lookupPrefix add attr isId
Diffstat (limited to 'ext/dom/domimplementation.c')
-rw-r--r--ext/dom/domimplementation.c67
1 files changed, 16 insertions, 51 deletions
diff --git a/ext/dom/domimplementation.c b/ext/dom/domimplementation.c
index fccae0b..dd255a2 100644
--- a/ext/dom/domimplementation.c
+++ b/ext/dom/domimplementation.c
@@ -132,10 +132,9 @@ PHP_FUNCTION(dom_domimplementation_create_document)
xmlNode *nodep;
xmlDtdPtr doctype = NULL;
xmlNsPtr nsptr = NULL;
- int ret, uri_len = 0, name_len = 0;
+ int ret, uri_len = 0, name_len = 0, errorcode = 0;
char *uri, *name;
- xmlChar *prefix = NULL, *localname = NULL;
- xmlURIPtr uristruct;
+ char *prefix = NULL, *localname = NULL;
dom_object *doctobj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sso", &uri, &uri_len, &name, &name_len, &node) == FAILURE) {
@@ -155,58 +154,24 @@ PHP_FUNCTION(dom_domimplementation_create_document)
}
}
- if (uri_len > 0 || name_len > 0 || doctype != NULL) {
- if (name_len == 0 && uri_len > 0) {
- php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ if (name_len > 0) {
+ errorcode = dom_check_qname(name, &localname, &prefix, 1, name_len);
+ if (errorcode == 0 && uri_len > 0 && ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL)) {
+ errorcode = NAMESPACE_ERR;
}
- if (name_len > 0) {
- uristruct = xmlParseURI(name);
- if (uristruct->opaque != NULL) {
- prefix = xmlStrdup(uristruct->scheme);
- localname = xmlStrdup(uristruct->opaque);
- if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
- php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
- xmlFreeURI(uristruct);
- xmlFree(prefix);
- xmlFree(localname);
- RETURN_FALSE;
- }
- if (!strcmp (prefix, "xml") && strcmp(uri, XML_XML_NAMESPACE)) {
- php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
- xmlFreeURI(uristruct);
- xmlFree(prefix);
- xmlFree(localname);
- RETURN_FALSE;
- }
- } else {
- localname = xmlStrdup(name);
- }
-
- /* TODO: Test that localname has no invalid chars
- php_dom_throw_error(INVALID_CHARACTER_ERR, TSRMLS_CC);
- */
-
- xmlFreeURI(uristruct);
+ }
- if (uri_len > 0) {
- if ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL) {
- php_dom_throw_error(NAMESPACE_ERR, &return_value TSRMLS_CC);
- if (prefix != NULL) {
- xmlFree(prefix);
- }
- xmlFree(localname);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
- RETURN_FALSE;
- }
+ if (prefix != NULL) {
+ xmlFree(prefix);
+ }
- }
- if (prefix != NULL) {
- xmlFree(prefix);
- }
+ if (errorcode != 0) {
+ if (localname != NULL) {
+ xmlFree(localname);
}
+ php_dom_throw_error(errorcode, &return_value TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Namespace");
+ RETURN_FALSE;
}
/* currently letting libxml2 set the version string */