$dom = new DomDocument('1.0');
$books = $dom->appendChild($dom->createElement('books'));
$book = $books->appendChild($dom->createElement('book'));
$title = $book->appendChild($dom->createElement('title'));
$title->appendChild(
$dom->createTextNode('Great American Novel'));
$dom->formatOutput = true; // установка атрибута formatOutput
$dom->save('test1.xml');
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="test1.xml"');
$dom = new DomDocument('1.0');
$books = $dom->appendChild($dom->createElement('books'));
$book = $books->appendChild($dom->createElement('book'));
$title = $book->appendChild($dom->createElement('title'));
$title->appendChild(
$dom->createTextNode('Great American Novel'));
$dom->formatOutput = true; // установка атрибута formatOutput
header('Content-Type: application/octet-stream');
echo $dom->saveXML();
function forceDownload($xml)
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/xml");
header("Content-Disposition: attachment; filename=" . basename($xml) . ";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($xml));
readfile($xml);
}