47

This is the XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<name>Sample Document</name>
<type>document</type>
<url>http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+Document&amp;titletype=Title&amp;fontsize=9&amp;fontface=Arial&amp;spacing=1.0&amp;text=&amp;wordcount3=0</url>
</document>

<document>
<name>Sample</name>
<type>document</type>
<url>http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+Document&amp;titletype=Title&amp;fontsize=9&amp;fontface=Arial&amp;spacing=1.0&amp;text=&amp;</url>
</document>

When I open it it says: This page contains the following errors: error on line 8 at column 1: Extra content at the end of the document

But when there is only this:

<document>
<name>Sample</name>
<type>document</type>
<url>http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+Document&amp;titletype=Title&amp;fontsize=9&amp;fontface=Arial&amp;spacing=1.0&amp;text=&amp;</url>
</document>

Why is it saying this when there is two?

electrikmilk
  • 1,013
  • 1
  • 11
  • 23
  • Possible duplicate of [Error on line 2 at column 1: Extra content at the end of the document](http://stackoverflow.com/questions/4544272/error-on-line-2-at-column-1-extra-content-at-the-end-of-the-document) – Dima Fomin Dec 11 '16 at 10:32

3 Answers3

83

You need a root node

<?xml version="1.0" encoding="ISO-8859-1"?>    
<documents>
    <document>
        <name>Sample Document</name>
        <type>document</type>
        <url>http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+Document&amp;titletype=Title&amp;fontsize=9&amp;fontface=Arial&amp;spacing=1.0&amp;text=&amp;wordcount3=0</url>
    </document>

    <document>
        <name>Sample</name>
        <type>document</type>
        <url>http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+Document&amp;titletype=Title&amp;fontsize=9&amp;fontface=Arial&amp;spacing=1.0&amp;text=&amp;</url>
    </document>
</documents>
Lotok
  • 4,517
  • 1
  • 34
  • 44
5

I've found that this error is also generated if the document is empty. In this case it's also because there is no root element - but the error message "Extra content and the end of the document" is misleading in this situation.

Dave
  • 3,273
  • 1
  • 17
  • 15
0

I also had this error when quotes around text (like version and encoding) were curly quotes, not straight quotes.

Mark
  • 11
  • 2