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);
+ char *prefix = SXE_NS_PREFIX(ns);
+ if (zend_hash_exists(Z_ARRVAL_P(return_value), prefix, strlen(prefix) + 1) == 0) {
+ add_assoc_string(return_value, prefix, (char*)ns->href, 1);
+ }
}
static void sxe_add_namespaces(php_sxe_object *sxe, xmlNodePtr node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
}
/* }}} */
-static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlDocPtr doc, xmlNodePtr node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
+static void sxe_add_registered_namespaces(php_sxe_object *sxe, xmlNodePtr node, zend_bool recursive, zval *return_value TSRMLS_DC) /* {{{ */
{
- xmlNsPtr *ns = xmlGetNsList(doc, node);
-
- while (ns && ns[0]) {
- sxe_add_namespace_name(return_value, ns[0]);
- ns++;
- }
+ xmlNsPtr ns;
- if (recursive) {
- node = node->children;
- while (node) {
- sxe_add_registered_namespaces(sxe, doc, node, recursive, return_value TSRMLS_CC);
- node = node->next;
+ if (node->type == XML_ELEMENT_NODE) {
+ ns = node->nsDef;
+ while (ns != NULL) {
+ sxe_add_namespace_name(return_value, ns);
+ ns = ns->next;
+ }
+ if (recursive) {
+ node = node->children;
+ while (node) {
+ sxe_add_registered_namespaces(sxe, node, recursive, return_value TSRMLS_CC);
+ node = node->next;
+ }
}
}
}
-/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursve])
+/* {{{ proto string SimpleXMLElement::getDocNamespaces([bool recursive])
Return all namespaces registered with document */
SXE_METHOD(getDocNamespaces)
{
sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
- sxe_add_registered_namespaces(sxe, (xmlDocPtr)sxe->document->ptr, xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr), recursive, return_value TSRMLS_CC);
+ sxe_add_registered_namespaces(sxe, xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr), recursive, return_value TSRMLS_CC);
}
/* }}} */
$xml =<<<EOF
<?xml version='1.0'?>
<xhtml:html xmlns:html='http://www.w3.org/1999/xhtml' xmlns:xhtml='http://www.w3.org/TR/REC-html40'>
-<xhtml:head><xhtml:title>bla</xhtml:title></xhtml:head>
+<xhtml:head><xhtml:title xmlns:xhtml='http://www.w3.org/TR/REC-html401'>bla</xhtml:title></xhtml:head>
<xhtml:body html:title="b">
<html:h1>bla</html:h1>
<foo:bar xmlns:foo='foobar' xmlns:baz='foobarbaz'/>
$xml =<<<EOF
<?xml version='1.0'?>
-<html xmlns='http://www.w3.org/1999/xhtml'/>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head><title xmlns='http://www.w3.org/TR/REC-html40'>bla</title></head>
+</html>
EOF;
$sxe = simplexml_load_string($xml);