formatOutput = true; $teacherXML=$doc->appendChild($doc->createElement("teachers")); foreach($rawTeacher as $teacher) $teacherXML->appendChild($doc->createElement('teacher',$teacher['OPETTAJANIMI'])); echo $doc->saveXML(); ?>