lastChild; $trg_doc = new DOMDocument(); $root = $trg_doc->createElement("list"); $trg_doc->appendChild($root); $studs = $start->getElementsByTagName("student"); foreach( $studs as $stud ){ //reading - as in Average_1 $the_name = $stud->getAttribute("name"); $the_mark = $stud->getAttribute("mark"); //Building - as in Build2fromText $new_stud = $trg_doc->createElement("student"); $root->appendChild($new_stud); $name = $trg_doc->createElement("name"); $new_stud->appendChild($name); $name->appendChild($trg_doc->createTextNode($the_name)); $mark = $trg_doc->createElement("mark"); $new_stud->appendChild($mark); $mark->appendChild($trg_doc->createTextNode($the_mark)); } return $trg_doc; }// transform1_2 function one2Two($fileIn, $fileOut){ $doc = new DOMDocument(); $doc->load($fileIn); $res = transform1_2($doc); $res->save($fileOut); }//one2Two one2Two($argv[1], $argv[2]); ?>