What are some best practices for handling namespaces in XPath queries when working with XML documents in PHP?

When working with XML documents in PHP, it is important to handle namespaces properly in XPath queries to accurately select nodes. One best practice is to register the namespaces using the `registerXPathNamespace` method before executing the XPath query. This allows you to reference the namespaces in your XPath expressions. Additionally, you can use prefixes in your XPath queries to specify the namespace of the elements you want to select.

$xml = new DOMDocument();
$xml->load('example.xml');

$xpath = new DOMXPath($xml);
$xpath->registerNamespace('ns', 'http://www.example.com/ns');

$query = '//ns:element';
$elements = $xpath->query($query);

foreach ($elements as $element) {
    echo $element->nodeValue . PHP_EOL;
}