1

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

3
  • Use "\n" and "\t" for output format Commented Jul 2, 2012 at 14:13
  • thanks for this i have tried these and they just show up as text Commented Jul 2, 2012 at 14:16
  • Make sure you are use double quotes " (not single quote ') with \n and \t Commented Jul 2, 2012 at 14:20

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.