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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8189117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 15:01:34  来源:igfitidea点击:

XML Parsing error: Extra content at the end of the document

xmlparsing

提问by input

I am getting this error in my xml file: XML Parsing error: Extra content at the end of the document

我在我的 xml 文件中收到此错误: XML Parsing error: Extra content at the end of the document

I am using Notepad++ and it shows the second word in red in the header tags <ABC BLAH>hello</ABC BLAH>- it shows the BLAHin red. Because of this, I assume the problem is in the whitespace in the header tags and throws a validation error at that line. How do I resolve this?

我正在使用 Notepad++,它在标题标签中以红色显示第二个单词<ABC BLAH>hello</ABC BLAH>- 它以红色显示BLAH。因此,我假设问题出在标题标签中的空白处,并在该行引发验证错误。我该如何解决?

This is the xml file:

这是xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <row>
        <Order>1</Order>
        <Requirements>ABC</Requirements>
        <Testing Procedures>blah blah </Testing Procedures> 
        <Assessment Observations / Comments>blah blah</Assessment Observations / Comments> <-- throws Parsing error at this line.
    </row>
</rows>

采纳答案by FailedDev

<Testing Procedures="">blah blah </Testing Procedures>

Can't have spaces in element names.

元素名称中不能有空格。

<Assessment Observations="" / Comments>blah blah</Assessment Observations / Comments>

Also this has multiple errors. Maybe you meant this ? :

这也有多个错误。也许你是这个意思?:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
  <row>
    <Order>1</Order>
    <Requirements>ABC</Requirements>
    <TestingProcedures foo=" ">blah blah </TestingProcedures>
    <Assessment Observations="/ Comments>blah blah"/>
    <Assessment Observations=" / Comments"/>
  </row>
</rows>

You have multiple errors. Can't really tell what you are trying to do.

您有多个错误。无法真正说出您正在尝试做什么。

OK .xml 101:

好的 .xml 101:

XML doesn't permit spaces in element names.

XML 不允许元素名称中有空格。

If you don't close the element name you can specify attributes like this.

如果您不关闭元素名称,您可以指定这样的属性。

<foo bar="I am an attribute" lol="Me too"> Here you can specify text, or other elements </foo>

In addition if an element doesn't contain another one , or a text you can use the shorthand notation

此外,如果一个元素不包含另一个元素或文本,您可以使用速记符号

<foo attribute="bar"/>

I suggest you read some basic tutorialfor this.

我建议您为此阅读一些基本教程