I have a problem while creating an xml file in php.I am not getting th root element.But all other elements are been outputted in the result.What might be the reason????Any help would be appreciated.The code is depicted below.order is my root element.
<?php
$url='success.xml';
//$xml = simplexml_load_file($url);
$name = htmlentities($_POST);
$age = htmlentities($_POST);
$doc = new DOMDocument();
$root=$doc->createElement("order");
$doc->appendChild($root);
$textareaNode = $doc->createElement("name");
$textNode = $doc->createTextNode($name);
$textareaNode->appendChild($textNode);
$doc->appendChild($textareaNode);
$textareaNode = $doc->createElement("age");
$textNode = $doc->createTextNode($age);
$textareaNode->appendChild($textNode);
$doc->appendChild($textareaNode);
//header('Content-Type: text/xml');
echo $doc->save($url);
?>
the above is my getdata.php page
<html>
<body>
<form name="form" action="getdata.php" method="post">
<table>
<tr>
<td>name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>age</td>
<td><input type="text" name="age" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
the above is my test.php page.
i got the output as
<?xml version="1.0"?>
<order/>
<name>patrick</name>
<age>23</age>