Writing XML file Issue with DOM Object

General discussions related to php

Moderators: macek, egami, gesf

masoom
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Oct 23, 2012 1:31 am

Writing XML file Issue with DOM Object

Postby masoom » Tue Oct 23, 2012 1:35 am

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

Code: Select all


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



Here is my XML file

Code: Select all


<?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

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests