What are some common pitfalls when using XPath in PHP to extract data from XML files?

One common pitfall when using XPath in PHP to extract data from XML files is not properly registering the namespace prefixes used in the XML document. To solve this issue, you can register the namespace prefixes with the `registerXPathNamespace` method before querying the XML document.

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

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

$nodes = $xpath->query('//ns:element');
foreach ($nodes as $node) {
    echo $node->nodeValue;
}