Reputation: 3686
I have the following code that creates and downloads an xml formatted page.
My issue is when this is viewed in a browser etc I get the xml tree view that i am after, but when i open the page in notepad etc i get it all on one line.
How can i get this to output the file so that it is done as a proper xml tree within notepad etc
header('Content-Disposition: attachment; filename="itunes_' . $_SESSION['xmlfilename'] . '.xml"');
header('Content-Transfer-Encoding: binary');
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>';
require_once 'inc/config.php';
require 'class.itunesxmlcls.php';
$d = new iTunesXML();
echo $d->CreateItunesXML($_SESSION['update']['id']);
Many Thanks
Upvotes: 1
Views: 267
Reputation: 59699
Use the DOMDocument
class to format it for you by setting the formatOutput
flag to true
before you load the XML, like so:
$d = new iTunesXML();
$xml = $d->CreateItunesXML($_SESSION['update']['id']);
$doc = new DOMDocument;
$doc->formatOutput = true;
$doc->loadXML( $xml);
echo $doc->saveXML();
Upvotes: 2