simplexml_debug
simplexml_debug copied to clipboard
Attributes in default namespace behave oddly
There seems to be a bug (or misfeature?) in SimpleXML where attributes in the default namespace don't show if you call ->attributes($default_namespace_uri)
rather than ->attributes('', true)
.
Because of simplexml_dump
's attempts to display namespace information, this leads to data disappearing from view with innocuous XML like this:
<?php
include 'simplexml_dump.php';
$xml = <<<XML
<?xml version="1.0"?>
<Foo xmlns="http://example.com">
<Bob InvisibleAttribute="You ain't seen me, right?">
<MaskingChildElement />
</Bob>
</Foo>
XML;
$sx_Foo = simplexml_load_string($xml);
simplexml_dump($sx_Foo->Bob);
A bit of research shows this may actually be correct behaviour, if not exactly user-friendly: an attribute with no qualifier is technically in no namespace at all, even if a default namespace was declared.
See e.g. http://stackoverflow.com/questions/10672635/xml-namespaces-and-unprefixed-attributes for discussion of this slightly baffling area of XML namespace logic...
Also need to work out how this affects simplexml_tree
: if we suggest that the full URI is used for all calls to ->children()
(see #5) then calls to such "namespaceless attributes" will have to be expressed as ->attributes()->foo
rather than ['foo']
.