How can XPath be used to work with namespaces in XML when using SimpleXML in PHP?

When working with XML namespaces in SimpleXML in PHP, XPath queries need to specify the namespace prefix in order to correctly select nodes. This can be done by registering the namespace with the `registerXPathNamespace()` method and then using the registered prefix in the XPath query.

$xml = <<<XML
<root xmlns:ns="http://example.com">
  <ns:element>Value</ns:element>
</root>
XML;

$simplexml = simplexml_load_string($xml);

$simplexml->registerXPathNamespace('ns', 'http://example.com');
$elements = $simplexml->xpath('//ns:element');

foreach ($elements as $element) {
    echo $element . "\n";
}