Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:42:57+00:00 2026-06-15T16:42:57+00:00

I am getting error while loading the xml file. I got many answers related

  • 0

I am getting error while loading the xml file. I got many answers related to the topic but I really could not find why this error maybe coming in my file.

Warning: DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Extra content at the end of the document 

When I am running the file, it runs successfully, but when I reload it, it gives the above error instead of adding another node. But, next time when I reload it runs successfully again. This is happening alternatively. Please someone tell me why is this happening and how to solve the problem.

I am using this php code to edit the xml file:

<?php
$dom = new DomDocument("1.0", "UTF-8");
$dom->load('filename.xml');

$noteElem = $dom->createElement('note');
$toElem = $dom->createElement('to', 'Chikck');
$fromElem = $dom->createElement('from', 'ewrw');

$noteElem->appendChild($toElem);
$noteElem->appendChild($fromElem);

$dom->appendChild($noteElem);
$dom->formatOutput = TRUE;
//$xmlString = $dom->saveXML();
//echo $xmlString;
$dom->save('filename.xml');
?>

This is the xml file I am editing:

<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Chikck</to>
  <from>ewrw</from>
</note>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:42:59+00:00Added an answer on June 15, 2026 at 4:42 pm

    The extra content error is caused by having two of the same node, in this case the note node, as a root element.

    You could add a new root element notes for example, and then add more note elements within that.

    Here’s an example using the simplexml library (just because I use this one and I’m familiar with it)

    New filename2.xml: (with added notes element as root)

    <?xml version="1.0" encoding="UTF-8"?>
    <notes>
        <note>
            <to>Chikck</to>
            <from>ewrw</from>
        </note>
    </notes>
    

    PHP script:

    <?php
        $xml = simplexml_load_file('filename2.xml');
        $note = $xml->addChild('note');
        $to = $note->addchild('to', 'Chikck');
        $from = $note->addChild('from', 'ewrw');
        $xml->asXML('filename2.xml');
    ?>
    

    filename2.xml after running script:

    <?xml version="1.0" encoding="UTF-8"?>
    <notes>
        <note>
            <to>Chikck</to>
            <from>ewrw</from>
        </note>
        <note>
            <to>Chikck</to>
            <from>ewrw</from>
        </note>
    </notes>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the below mentioned error while loading the JSF page. The page
I am getting this error when running ./manage.py migrate app_name While loading migration 'whatever.0001_initial':
Probably a simple question, but I'm not that good with loading files… Getting my
I am getting this error while loading a custom dijit. I have done this
I am getting the following error while trying to read from an excel file
I am getting this error in webview while loading this url : http://www.thumbzine.com/rssfeed.php?vol=104 Error
While running some code I am getting a unhanded exception for file not found
I'm getting this error in my application: # bin/ladvd -h bin/ladvd: error while loading
Getting Out of memory error while loading large string from the server. This is
I'm having an error while loading an mp3 player, here is what I getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.