What is the significance of XML namespaces in PHP when parsing XML files?

When parsing XML files in PHP, XML namespaces are important as they allow for unique identification of elements and attributes within the XML document. Without properly handling namespaces, you may encounter issues with accessing and manipulating specific elements or attributes in the XML file.

// Create a new XML parser
$xml = new XMLReader();
$xml->open('example.xml');

// Iterate through the XML document
while($xml->read()) {
    // Check if the current node has a specific namespace
    if ($xml->namespaceURI === 'http://example.com/ns') {
        // Process the node within the specified namespace
        echo $xml->localName . ': ' . $xml->readString() . PHP_EOL;
    }
}

// Close the XML parser
$xml->close();