Toto12
from a text file
*/
function doc2fromText($fileName){
$doc = new DOMDocument();
$root = $doc->createElement("list");
$doc->appendChild($root);
$lines = file($fileName);
foreach( $lines as $line ){
$name_mark = split("[ \t]+", $line);
$the_name = $name_mark[0];
$the_mark = rtrim($name_mark[1]);
$stud = $doc->createElement("student");
$root->appendChild($stud);
$name = $doc->createElement("name");
$stud->appendChild($name);
$name->appendChild($doc->createTextNode($the_name));
$mark = $doc->createElement("mark");
$stud->appendChild($mark);
$mark->appendChild($doc->createTextNode($the_mark));
}
return $doc;
}// doc1fromText
function build2fromText($fileIn, $fileOut){
$doc = doc2fromText($fileIn);
$doc->save($fileOut);
}
build2fromText($argv[1], $argv[2]);
?>