CSV -> XML
formatOutput=true;
$xmlRoot = $xmlDoc->createElement("data");
$xmlDoc->appendChild($xmlRoot);
// FILL XML FILE WITH CSV DATA
while(($row_array = fgetcsv($fp, 0, ";")) !== false){
// skip emty value
if ($row_array === null || $row_array === []) {
continue;
}
// create sub elemente
$xmlSchueler = $xmlDoc->createElement("schuelerdata");
// for the count of elements in a row do this
for ($i = 0; $i < count($row_array); $i++){
// make sure there is a header to row
if (!isset($header_array[$i])){
continue;
}
// get current collumn
$column = $header_array[$i];
echo "$row_array[$i]
";
// create a new element with name of column and row data
$xmlSchuelerDaten = $xmlDoc->createElement($column, $row_array[$i]);
$xmlSchueler->appendChild($xmlSchuelerDaten);
}
// save element
$xmlRoot-> appendChild($xmlSchueler);
}
// Save whole XML file
$fileXml = "e2fi2.xml";
$xmlDoc->save(__DIR__ . "/$fileXml");