如果文件先前存在,则此代码有效,但如果文件不存在,则此代码无效。
$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');
更新代码
$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);
}