}
/* }}} */
+#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;
}
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;
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++;
}
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"]=>
["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) {
[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===