How can namespaces be effectively registered in PHP when working with XML files?

When working with XML files in PHP, namespaces need to be registered to correctly parse and manipulate the XML data. This can be done by using the `registerXPathNamespace()` method to associate a prefix with a namespace URI. This allows for easy querying and manipulation of elements within the XML document that belong to the specified namespace.

$xml = new SimpleXMLElement($xmlString);

$xml->registerXPathNamespace('ns', 'http://www.example.com/namespace');

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