How can PHP handle XML files with multiple instances of the root element?

When handling XML files with multiple instances of the root element, PHP can parse the XML file using SimpleXML and iterate over each instance of the root element using a loop. This allows PHP to access and manipulate each instance separately.

$xml = <<<XML
<root>
    <item>Item 1</item>
</root>
<root>
    <item>Item 2</item>
</root>
XML;

$items = new SimpleXMLElement($xml);

foreach ($items as $item) {
    echo $item->item . "\n";
}