There's a couple of ways to do this. I'm not entirely familiar with php's XML functions, but I am fairly familiar with the file functions. Here is an example:
$filename = "xmlfile.xml";
$file = file($filename); //place the old contents in an array
$open = fopen($filename, 'w'); //open the file for writing, clearing it
//this is the new node of xml
$newnode = " <lang>\n<code>fr</code>\n<name>French</name>\n</lang>\n";
//first, write the two head lines of the xml file back to it
fwrite($open, $file[0]);
fwrite($open, $file[1]);
//now write your newest node
fwrite($open, $newnode);
//now write the remainder of the old contents to the file
for ($i = 2; $i <= count($file); $i++) {
fwrite($open, $file[$i]);
}
fclose($open);
EDIT: Fixed a typo at the end of the $newnode line (was \b, changed to \n)