Log in

View Full Version : Resolved Writing XML file Issue with DOM Object



Masoom
10-22-2012, 09:08 PM
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

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);
}


my xml file like this


<?xml version="1.0" encoding="iso-8859-1"?>
<record>
<title>Masoom</title>
<starttime>12</starttime>
</record>
<record>
<title>Masoom</title>
<starttime>12</starttime>
</record>

Hope to hear from you soon
Regards
Masoom

Masoom
10-23-2012, 11:01 AM
i have solved the problem
I didnt have root element on my xm file