Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML错误:文档末尾有额外内容_Xml_Xml Parsing - Fatal编程技术网

XML错误:文档末尾有额外内容

XML错误:文档末尾有额外内容,xml,xml-parsing,Xml,Xml Parsing,这是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;titl

这是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>
当有两个节点时,为什么会这样说?

您需要一个根节点

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

样本文件
文件
http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+文件及;titletype=标题&;fontsize=9&;fontface=Arial&;间距=1.0&;text=&;wordcount3=0
样品
文件
http://nsc-component.webs.com/Office/Editor/new-doc.html?docname=New+文件及;titletype=标题&;fontsize=9&;fontface=Arial&;间距=1.0&;text=&;

我发现,如果文档为空,也会生成此错误。在这种情况下,这也是因为没有根元素,但在这种情况下,错误消息“Extra content and the end of the document”(额外内容和文档结尾)会产生误导。

根节点可能是任何内容。我刚才用了
而不是
<?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>