Results 1 to 2 of 2

Thread: Writing XML file Issue with DOM Object

  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Code:
    <?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
    Last edited by Masoom; 10-22-2012 at 09:53 PM. Reason: Format: Php ([php][/php]) and Code ([code][/code]) Tags

  2. #2
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i have solved the problem
    I didnt have root element on my xm file
    Last edited by jscheuer1; 10-23-2012 at 11:04 AM. Reason: Format

Similar Threads

  1. Writing only last object in xml
    By I am Abby in forum PHP
    Replies: 4
    Last Post: 05-12-2010, 04:42 PM
  2. Writing and reading a file..
    By Jeffreyv1987 in forum PHP
    Replies: 2
    Last Post: 11-14-2009, 05:38 PM
  3. writing to a file on server using js
    By vijayrajesh98 in forum JavaScript
    Replies: 3
    Last Post: 11-12-2008, 03:48 PM
  4. PHP File Writing
    By matthewbluewars in forum PHP
    Replies: 15
    Last Post: 06-05-2008, 09:00 PM
  5. Create object; load file in the object
    By molendijk in forum JavaScript
    Replies: 0
    Last Post: 03-09-2008, 07:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •