XML 错误消息:文档末尾的额外内容
Posted
技术标签:
【中文标题】XML 错误消息:文档末尾的额外内容【英文标题】:XML error message: Extra content at the end of the document 【发布时间】:2015-05-08 21:04:43 【问题描述】:我对这个 XML 和网络世界真的很陌生。如果有人可以帮助我,我将不胜感激。这可能只是一个小错误,但我找不到解决方法。它。我编写了一个 XML 文档,但收到一条错误消息:
此页面包含以下错误:
第 6 行第 1 列的错误:文档末尾的额外内容
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="student_faculty_directory.css"?>
<haccdirectory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="student_faculty_directory_Schema.xsd" />
<haccdirectory> <!--this is where the ERROR occurs-->
<s:student xmlns:s="http://www.hacc.info.edu/student=dir">
<class101>
<s:name>Austin Tang</s:name>
<s:info>
<s:age>28</s:age>
<s:gender>Male</s:gender>
<s:major>Web Development</s:major>
<s:enrollment>SPR12</s:enrollment>
<s:transferstudent>No</s:transferstudent>
<s:id>H01179944</s:id>
</s:info>
<s:name>Jeremy Riddle</s:name>
<s:info>
<s:age>21</s:age>
<s:gender>Male</s:gender>
<s:major>Web Design</s:major>
<s:enrollment>SPR13</s:enrollment>
<s:transferstudent>Yes</s:transferstudent>
<s:id>H01539441</s:id>
</s:info>
<s:name>Debbie Scissors</s:name>
<s:info>
<s:age>19</s:age>
<s:gender>Male</s:gender>
<s:major>Web Development</s:major>
<s:enrollment>FAL14</s:enrollment>
<s:transferstudent>No</s:transferstudent>
<s:id>H01570984</s:id>
</s:info>
<s:name>Craig Davidson</s:name>
<s:info>
<s:age>22</s:age>
<s:gender>Male</s:gender>
<s:major>Web Development</s:major>
<s:enrollment>SPR14</s:enrollment>
<s:transferstudent>Yes</s:transferstudent>
<s:id>H01578433</s:id>
</s:info>
<s:name>Justin Beer</s:name>
<s:info>
<s:age>24</s:age>
<s:gender>Male</s:gender>
<s:major>Web Design</s:major>
<s:enrollment>SPR13</s:enrollment>
<s:transferstudent>No</s:transferstudent>
<s:id>H01091349</s:id>
</s:info>
<s:name>Melody Herman</s:name>
<s:info>
<s:age>19</s:age>
<s:gender>Female</s:gender>
<s:major>Web Design</s:major>
<s:enrollment>SPR12</s:enrollment>
<s:transferstudent>No</s:transferstudent>
<s:id>H01992341</s:id>
</s:info>
</class101>
</s:student>
<f:faculty xmlns:f="http://www.hacc.info.edu/faculty-dir">
<teacher>
<f:name>Andre Miller</f:name>
<f:information>
<f:age>39</f:age>
<f:gender>Male</f:gender>
<f:hiredate>2003-05-23</f:hiredate>
<f:id>H01908314</f:id>
<f:campus>Lancaster</f:campus>
</f:information>
<f:name>Melody Wright</f:name>
<f:information>
<f:age>32</f:age>
<f:gender>Female</f:gender>
<f:hiredate>2002-07-12</f:hiredate>
<f:id>H01809312</f:id>
<f:campus>Gettysburg</f:campus>
</f:information>
<f:name>Andrew Yoder</f:name>
<f:information>
<f:age>44</f:age>
<f:gender>Male</f:gender>
<f:hiredate>2001-08-12</f:hiredate>
<f:id>H01782354</f:id>
<f:campus>Harrisburg</f:campus>
</f:information>
<f:name>Heather Miller</f:name>
<f:information>
<f:age>50</f:age>
<f:gender>Female</f:gender>
<f:hiredate>2001-07-31</f:hiredate>
<f:id>H01742121</f:id>
<f:campus>Harrisburg</f:campus>
</f:information>
<f:name>Stephanie King</f:name>
<f:information>
<f:age>37</f:age>
<f:gender>Female</f:gender>
<f:hiredate>2012-09-01</f:hiredate>
<f:id>H01922111</f:id>
<f:campus>Lancaster</f:campus>
</f:information>
<f:name>Robert Freeman</f:name>
<f:information>
<f:age>31</f:age>
<f:gender>Male</f:gender>
<f:hiredate>2014-09-10</f:hiredate>
<f:id>H01801154</f:id>
<f:campus>Gettysburg</f:campus>
</f:information>
<f:name>Casey Stevenson</f:name>
<f:information>
<f:age>31</f:age>
<f:gender>Female</f:gender>
<f:hiredate>2014-05-30</f:hiredate>
<f:id>H01642029</f:id>
<f:campus>Harrisburg</f:campus>
</f:information>
</teacher>
</f:faculty>
</haccdirectory>
【问题讨论】:
您的 Xml 文档有多个根元素 - 第一个在第 3 行(没有任何内容),第 6 行的<haccdirectory>
是第二个元素。合并第 3 行和第 6 行,您的问题就会消失。
【参考方案1】:
第 3 行的尾部斜杠表示您在同一个声明中打开和关闭了根元素。
XML 解析器告诉您该文档的顶部有一个非常简单的文档,即:
<haccdirectory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="student_faculty_directory_Schema.xsd" />
之后的一切都是多余的。
我认为结尾的斜杠不应该在那里。
【讨论】:
以上是关于XML 错误消息:文档末尾的额外内容的主要内容,如果未能解决你的问题,请参考以下文章
BootstrapVue VeeValidate - 当表单无效时显示额外的错误消息