I've written the underneath PHP script and it works at a basic level but i'm trying to add in a bit of finesse on the XML presentation side and i'm falling flat on my face.
What it does is create an XML file from a plain old text file. It works and the XML file is well-formed. However, i did try and dynamically add in some XSL and Schema links, when the XMl file is created, so that the file could be validated. Whatever way i try to do it, the information relevant to the XSL and Schema links appears above the XML file declaration itself. This leads to the document not being well-formed and i'm tearing my hair out.
Just how would i go about adding these in? As you can no doubt guess, i'm new to PHP and i'm sure i'm asking something simple so any help would be gratefully appreciated. Thank you.
What it does is create an XML file from a plain old text file. It works and the XML file is well-formed. However, i did try and dynamically add in some XSL and Schema links, when the XMl file is created, so that the file could be validated. Whatever way i try to do it, the information relevant to the XSL and Schema links appears above the XML file declaration itself. This leads to the document not being well-formed and i'm tearing my hair out.
Just how would i go about adding these in? As you can no doubt guess, i'm new to PHP and i'm sure i'm asking something simple so any help would be gratefully appreciated. Thank you.
Code:
<?php
$data0 = $_POST["name"];
$data1 = $_POST["age"];
$data2 = $_POST["rules"];
include("signoff1.inc");
$thankyou = ", thank you.";
echo "<h3>";
echo $name.$thankyou;
echo "</h3>";
include("signoff2.inc");
$fp = fopen ('signoff.txt', 'ab');
fwrite ($fp, "$name \n");
fwrite ($fp, "$age \n");
fwrite ($fp, "$rules \n");
fclose ($fp);
$fields = 3;
$data = file('signoff.txt');
$n = count($data);
$doc = domxml_new_doc('1.0');
$root = $doc->add_root('signoff');
$member = $root->new_child('member','');
for ($i=0; $i<=$n-$fields; $i+=$fields) {
$member->new_child('name',$data[$i]);
$member->new_child('age',$data[$i+1]);
$member->new_child('rules',$data[$i+2]);
if ($i+2 < $n-1) {
$member = $root->new_child('member','');
}
}
$fp = fopen('signoffs.xml','w+b');
if(!$fp) {
die('Error cannot create XML file');
}
fwrite($fp,$doc->dumpmem());
fclose($fp);
?>