Writing XML file Issue with DOM Object

hello
I am writing xml but i am getting this warning

Warning: DOMDocument::load(): Extra content at the end of the document in file:///C:/xampp/htdocs/ive/echo-hereweare.xml, line: 6 in C:\xampp\htdocs\ive\index.php on line 17

The following code runs two time fine then third time it deletes my xml nodes and put only the new nodes in the file
Here is my php code

php

if (file_exists($filename))
{
$xml = new DomDocument(‘1.0’,‘iso-8859-1’);
$xml->formatOutput = true;
$xml->load($filename);
$xml_record = $xml->createElement(“record”);
$xml_title = $xml->createElement(“title”);
$title_value = $xml->createTextNode($title);
$xml_title->appendChild($title_value);
$xml_record->appendChild($xml_title);
$xml_starttime = $xml->createElement(“starttime”);
$starttime_value = $xml->createTextNode($starttime);
$xml_starttime->appendChild($starttime_value);
$xml_record->appendChild($xml_starttime);
$xml->appendChild($xml_record);
$xml->save($filename);
}
else
{
$xml = new DomDocument(‘1.0’,‘iso-8859-1’);
$xml->formatOutput = true;
$xml_record = $xml->createElement(“record”);
$xml_title = $xml->createElement(“title”);
$title_value = $xml->createTextNode($title);
$xml_title->appendChild($title_value);
$xml_record->appendChild($xml_title);
$xml_starttime = $xml->createElement(“starttime”);
$starttime_value = $xml->createTextNode($starttime);
$xml_starttime->appendChild($starttime_value);
$xml_record->appendChild($xml_starttime);
$xml->appendChild($xml_record);
$xml->save($filename);
}

<?xml version="1.0" encoding="iso-8859-1"?> Masoom 12 Masoom 12

Hope to hear from you soon
Regards
Masoom

Sponsor our Newsletter | Privacy Policy | Terms of Service