To run an xpath query on an XML document that has a namespace, the namespace must be registered with SimpleXMLElement::registerXPathNamespace() before running the query. If the XML document namespace does not include a prefix, you must make up an arbitrary one, and then use it in your query.<?php$strXml= <<<XML<?xml version="1.0" encoding="UTF-8"?><mydoc xmlns="http://www.url.com/myns"> <message>Test message</message></mydoc>XML;$xmlDoc=new \SimpleXMLElement($strXml);foreach($xmlDoc->getDocNamespaces() as $strPrefix => $strNamespace) { if(strlen($strPrefix)==0) { $strPrefix="a"; //Assign an arbitrary namespace prefix. } $xmlDoc->registerXPathNamespace($strPrefix,$strNamespace);}print($xmlDoc->xpath("//a:message")[0]); //Use the arbitrary namespace prefix in the query.?>This will output:Test message