$doc = new DomDocument(); $root = $doc->createElement('root'); $child = $doc->createElement('child', 'Hello World'); $root->appendChild($child); $doc->appendChild($root); $doc->save('file.xml');
$doc = new DomDocument(); $root = $doc->createElement('root'); $child = $doc->createElement('child', 'Hello World'); $root->appendChild($child); $doc->appendChild($root); $xml = $doc->saveXML(); echo $xml;These examples demonstrate the basic usage of DomDocument save method for saving an XML document. The package library for DomDocument is integrated into the PHP core, so there's no need to install any external libraries.