use \DOMDocument; $xmlUrl = 'http://example.com/data.xml'; $xmlString = file_get_contents($xmlUrl); $doc = DOMDocument::newFromUrl($xmlUrl); // Do something with the $doc objectIn this example, we are using the DOMDocument class to load an XML document from an external URL. We use the newFromUrl method to create a new instance of the DOMDocument class based on that URL. Package library: This method is a part of the DOM extension in PHP, which is included in the core PHP distribution.