$xml_header = '<?xml version="1.0" encoding="UTF-8"?><Example></Example>';
$xml = new SimpleXMLElement($xml_header);
$node1 = $xml->addChild('node');
$node1->addAttribute('id', '1');
$node1->addAttribute('name', 'node 1');
$subnode1 = $node1->addChild('subnode');
$subnode1->addAttribute('id', '1.1');
$subnode1->addAttribute('name', 'subnode 1.1');
$subnode2 = $node1->addchild('subnode');
$subnode2->addAttribute('id', '1.2');
$subnode2->addAttribute('name', 'subnode 1.2');
$inner_node1 = $subnode2->addChild('inner_node');
$inner_node1->addAttribute('id', '1.2.1');
$inner_node1->addAttribute('name', 'inner node 1.2.1');
header('Content-Disposition: attachment; filename="text.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo $xml->asXML();
This is a test code for generating and downloading an XML file as an attachment.
Everything works fine, but when i open the downloaded XML file in Notepad++, it is written in 2 lines of code ONLY:
<?xml version="1.0" encoding="UTF-8"?>
<Example><node id="1" name="node 1"><subnode id="1.1" name="subnode 1.1"/><subnode id="1.2"name="subnode 1.2"><inner_node id="1.2.1" name="inner node 1.2.1"/></subnode></node></Example>
Is it possidble the downloaded XML file to look like this ? Or it's the same thing ?
<?xml version=”1.0″ encoding=”UTF-8″?>
<Example>
<node id=”1″ name=”node 1″>
<subnode id=”1.1″ name=”subnode 1.1″/>
<subnode id=”1.2″ name=”subnode 1.2″>
<inner_node id=”1.2.1″ name=”inner node 1.2.1″/>
</subnode>
</node>
</Example>