What are some common errors that may occur when using XPath in PHP?

One common error when using XPath in PHP is not properly registering the XPath namespace. This can lead to XPath queries not returning the expected results. To solve this issue, make sure to register the namespace using the `registerNamespace` method before executing the XPath query.

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

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

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

foreach ($elements as $element) {
    // Process each element
}