【问题标题】:XML Error: Extra content at the end of the documentXML 错误:文档末尾的额外内容
【发布时间】:2013-05-27 12:09:24
【问题描述】:

这是 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>

当我打开它时,它显示:This page contains the following errors: error on line 8 at column 1: Extra content at the end of the 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>

当有两个时为什么要这样说?

【问题讨论】:

标签: xml xml-parsing


【解决方案1】:

我发现如果文档为空也会产生这个错误。在这种情况下,这也是因为没有根元素 - 但错误消息“额外内容和文档结尾”在这种情况下具有误导性。

【讨论】:

    【解决方案2】:

    你需要一个根节点

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

    【讨论】:

    • 好像根节点可以是任何东西。我刚刚使用了&lt;div&gt; 而不是&lt;documents&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多