]> granicus.if.org Git - php/commitdiff
- Handle default namespaces
authorMarcus Boerger <helly@php.net>
Tue, 1 Nov 2005 11:53:14 +0000 (11:53 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 1 Nov 2005 11:53:14 +0000 (11:53 +0000)
# Another time it shows xml is far from being simple

ext/simplexml/simplexml.c
ext/simplexml/tests/025.phpt

index a2030684fa94843f3a66edf4b30e01e1742e8be9..f9bc29d5dd39b5cd3b957347d5a4ff0460f6128f 100644 (file)
@@ -1102,18 +1102,25 @@ SXE_METHOD(asXML)
 }
 /* }}} */
 
+#define SXE_NS_PREFIX(ns) (ns->prefix ? (char*)ns->prefix : "")
+
+static inline void sxe_add_namespace_name(zval *return_value, xmlNsPtr ns)
+{
+       add_assoc_string(return_value, SXE_NS_PREFIX(ns), (char*)ns->href, 1);
+}
+
 static void sxe_add_namespaces(php_sxe_object *sxe, xmlNodePtr node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
 {
        xmlAttrPtr  attr;
 
        if (node->ns) { 
-               add_assoc_string(return_value, (char*)node->ns->prefix, (char*)node->ns->href, 1);
+               sxe_add_namespace_name(return_value, node->ns);
        }
 
        attr = node->properties;
        while (attr) {
                if (attr->ns) { 
-                       add_assoc_string(return_value, (char*)attr->ns->prefix, (char*)attr->ns->href, 1);
+                       sxe_add_namespace_name(return_value, attr->ns);
                }
                attr = attr->next;
        }
@@ -1152,7 +1159,7 @@ SXE_METHOD(getNamespaces)
                if (node->type == XML_ELEMENT_NODE) {
                        sxe_add_namespaces(sxe, node, recursive, return_value TSRMLS_CC);
                } else if (node->type == XML_ATTRIBUTE_NODE && node->ns) {
-                       add_assoc_string(return_value, (char*)node->ns->prefix, (char*)node->ns->href, 1);
+                       sxe_add_namespace_name(return_value, node->ns);
                }
 next_iter:
                node = node->next;
@@ -1165,7 +1172,7 @@ static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlDocPtr doc, xm
        xmlNsPtr *ns = xmlGetNsList(doc, node);
 
        while (ns && ns[0]) {
-               add_assoc_string(return_value, (char*)ns[0]->prefix, (char*)ns[0]->href, 1);
+               sxe_add_namespace_name(return_value, ns[0]);
                ns++;
        }
 
index 4c048c7ced2370825e0117f8335a52934bdb62a0..fc2516efa599d8ec4884d2a8314027813a3c427b 100755 (executable)
@@ -23,8 +23,19 @@ var_dump($sxe->getNamespaces(true));
 var_dump($sxe->getDocNamespaces());
 var_dump($sxe->getDocNamespaces(true));
 
+$xml =<<<EOF
+<?xml version='1.0'?>
+<html xmlns='http://www.w3.org/1999/xhtml'/>
+EOF;
+
+$sxe = simplexml_load_string($xml);
+
+var_dump($sxe->getNamespaces());
+var_dump($sxe->getDocNamespaces());
+
 ?>
 ===DONE===
+<?php exit(0); ?>
 --EXPECTF--
 array(1) {
   ["xhtml"]=>
@@ -54,6 +65,14 @@ array(4) {
   ["baz"]=>
   string(9) "foobarbaz"
 }
+array(1) {
+  [""]=>
+  string(28) "http://www.w3.org/1999/xhtml"
+}
+array(1) {
+  [""]=>
+  string(28) "http://www.w3.org/1999/xhtml"
+}
 ===DONE===
 --UEXPECTF--
 array(1) {
@@ -84,4 +103,12 @@ array(4) {
   [u"baz"]=>
   string(9) "foobarbaz"
 }
+array(1) {
+  [u""]=>
+  string(28) "http://www.w3.org/1999/xhtml"
+}
+array(1) {
+  [u""]=>
+  string(28) "http://www.w3.org/1999/xhtml"
+}
 ===DONE===