How can namespaces be utilized in XPath queries to access elements within an XHTML document parsed with SimpleXML?

When working with XHTML documents parsed with SimpleXML in PHP, namespaces can be utilized in XPath queries to access specific elements within the document. This is necessary when the document uses XML namespaces to define elements. To access elements within a specific namespace, you can register the namespace with SimpleXML using the `registerXPathNamespace` method and then use the namespace prefix in your XPath queries.

$xml = new SimpleXMLElement($xhtml);
$xml->registerXPathNamespace('ns', 'http://www.w3.org/1999/xhtml');

$elements = $xml->xpath('//ns:elementName');
foreach ($elements as $element) {
    // Process the element
}