I have a variable with XML and I want to make it download using a download button and I can't find a way to do that. Below is the last part of the code. I want this "newxml" variable to download as a XML file. How can I do it?
<?php
require_once('b.php');
$json = file_get_contents('sample.json');
$php_array = json_decode($json, true);
header("Content-type: text/xml");
$xml = Array2XML::createXML('root-element-here', $php_array);
$newxml=$xml->saveXML();
echo $newxml;
$file = 'XML.xml';
file_put_contents($file, $newxml);
?>
I tried to make it downloadable like below and it makes and error. can someone please make this correct
<!DOCTYPE html>
<html>
<body>
<?php
require_once('b.php');
$json = file_get_contents('sample.json');
$php_array = json_decode($json, true);
header("Content-type: text/xml");
$xml = Array2XML::createXML('root-element-here', $php_array);
$newxml=$xml->saveXML();
$file = 'XML.xml';
file_put_contents($file, $newxml);
?>
<a href="XML.xml" download="sample.xml">Download XML</a>
</body>
</html>
Here is the error message
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<html>
<body>
<a href="XML.xml" download="sample.xml">Download XML</a>
</body>
</html>