What are some common pitfalls when using SimpleXML Xpath queries in PHP?
One common pitfall when using SimpleXML Xpath queries in PHP is not properly handling namespaces. If your XML document uses namespaces, you need to register them before running your Xpath query. This can be done by using the `registerXPathNamespace` method on the SimpleXMLElement object.
$xml = simplexml_load_file('example.xml');
// Register namespaces
$xml->registerXPathNamespace('ns', 'http://example.com/ns');
// Run Xpath query
$results = $xml->xpath('//ns:element');
// Loop through results
foreach ($results as $result) {
// Do something with the result
}