This code works if file is previously expisting but if file doesn't exist this code doesnt work.\[code\]$doc = new DOMDocument(); $doc->version = '1.0'; $doc->encoding = 'ISO-8859-1'; $response = $doc->createElement('response'); $doc->appendChild($response); $response_type= $doc->createElement('response_type','Yes'); $response_id = $doc->createElement('response_id',$max_id_site); $response->appendChild($response_type); $response->appendChild($response_id); $doc->formatOutput = true; echo $doc->saveXML(); $doc->save('$filename_xml');\[/code\]updated code\[code\]$doc = new DOMDocument(); $doc->version = '1.0'; $doc->encoding = 'ISO-8859-1'; $response = $doc->createElement('response'); $doc->appendChild($response); $response_type= $doc->createElement('response_type','Yes'); $response_id = $doc->createElement('response_id',$max_id_site); $response->appendChild($response_type); $response->appendChild($response_id); $doc->formatOutput = true; echo $doc->saveXML(); if (! is_file($filename_xml)) { touch($filename_xml) or trigger_error("Can't Create File"); $doc->save($filename_xml); } \[/code\]