PHP, SimpleXML, XPath and namespaced attributes


This PHP bugfix is worth keeping an eye on when the next version is released, as it changes the behaviour of XPath selectors for namespaced attributes.

Previously (PHP <= 5.2.6) for an item like

<ns:foo xmlns:ns="">
  <ns:bar ns:baz="hello">goodbye</ns:bar>
you'd use
$xml = simplexml_load_string($xml_string);
$xml->registerXPathNamespace('ns', '');
$baz = $xml->xpath('ns:bar/@baz');
which obviously caused problems when there were multiple attributes with the same name but different namespaces. Now you have to use the namespace for selecting the attributes as well as the elements, as it should be.
$baz = $xml->xpath('ns:bar/@ns:baz');
It's not clear how this will affect selecting attributes using SimpleXML, which currently uses $bar['baz'], ignoring (as far as I know) namespaces on attributes.