PHP offers us XPath expressions when handling XML data through SimpleXML. This allows us to query for data in a great and quick way, but one thing baffled me when using it for the first time: it didn't work when querying for data with no namespace (default namespace). After quite a while looking for a solution on the web, it seems XPath needs the empty namespace to be registered. For example:
$xml = '
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
</movie>
</movies>
<movie>
<title>PHP: Behind the Parser</title>
</movie>
</movies>
'
$movies = new SimpleXMLElement($xml);
$namespaces = $movies->getDocNamespaces(true);
$movies->registerXPathNamespace('__empty_ns', $namespaces['']);
Now you can query using the __empty_ns namespace (or whatever is your favourite flavour in empty namespacing)!
$phpMovie = $movies->xpath('//__empty_ns:movie/title[.="PHP: Behind the Parser"]');