How to fix error: The markup in the document following the root element must be well-formed
How to fix error: The markup in the document following the root element must be well-formed
我将我的代码放在 XML 验证网站上,它给我这个错误:
Line 8: 4 The markup in the document following the root element must be well-formed.
有问题的行是 <xsl:output method = "html" doctype-system = "about:legacy-compat"/>
,行。
XML
<?xml version="1.0"?>
<!-- Fig. 15.21: sorting.xsl -->
<xsl:stylesheet version = "1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<!-- write XML declaration and DOCTYPE DTD information -->
*<xsl:output method = "html" doctype-system = "about:legacy-compat" />*
<!-- match document root -->
<xsl:template match="/"> -<html> <xsl:apply-templates/> </html>
</xsl:template>
一般情况
The markup in the document following the root element must be well-formed.
此错误表明您的 XML 在根元素之后有标记。
为了成为well-formed, XML must have exactly one root element,单根元素后不能有进一步的标记。
一个根元素示例(好)
<r>
<a/>
<b/>
<c/>
</r>
此错误的最常见来源是:
包括杂散或额外的关闭标签(错误):
<r>
<a/>
<b/>
<c/>
</r>
</r> <!-- shouldn't be here -->
故意有多个根元素(错误):
<a/>
<b/> <!-- second root element shouldn't be here -->
<c/> <!-- third root element shouldn't be here -->
无意中有多个根元素(错误):
<r/> <!-- shouldn't be self-closing -->
<a/>
<b/>
<c/>
</r>
解析与您想象的不同 XML(错误):
在提供给解析之前立即记录 XML
失败以确保解析器是 XML
看到与您认为看到的 XML 相同。常见的
这里的错误包括:
- 正在传递给 XML 文档的文件名
解析器与您认为的不同。
- XML 的缓冲区脏了。确保它已经
在添加 XML.
之前清除
- 管道中先前阶段的较早程序
在生成的解析之前更改 XML
此错误消息。
您的具体问题
在您的特定情况下,您的 XML 似乎有多个根元素,因为 xsl:stylesheet
元素过早关闭(上述情况 #3)。
改变
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
至
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
解决您眼前的问题,并添加结束标记,
</xsl:stylesheet>
如果您的真实文档中不存在。
这也可能因为文件中的空格错误而出现
我将我的代码放在 XML 验证网站上,它给我这个错误:
Line 8: 4 The markup in the document following the root element must be well-formed.
有问题的行是 <xsl:output method = "html" doctype-system = "about:legacy-compat"/>
,行。
XML
<?xml version="1.0"?>
<!-- Fig. 15.21: sorting.xsl -->
<xsl:stylesheet version = "1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<!-- write XML declaration and DOCTYPE DTD information -->
*<xsl:output method = "html" doctype-system = "about:legacy-compat" />*
<!-- match document root -->
<xsl:template match="/"> -<html> <xsl:apply-templates/> </html>
</xsl:template>
一般情况
The markup in the document following the root element must be well-formed.
此错误表明您的 XML 在根元素之后有标记。 为了成为well-formed, XML must have exactly one root element,单根元素后不能有进一步的标记。
一个根元素示例(好)
<r>
<a/>
<b/>
<c/>
</r>
此错误的最常见来源是:
包括杂散或额外的关闭标签(错误):
<r> <a/> <b/> <c/> </r> </r> <!-- shouldn't be here -->
故意有多个根元素(错误):
<a/> <b/> <!-- second root element shouldn't be here --> <c/> <!-- third root element shouldn't be here -->
无意中有多个根元素(错误):
<r/> <!-- shouldn't be self-closing --> <a/> <b/> <c/> </r>
解析与您想象的不同 XML(错误):
在提供给解析之前立即记录 XML 失败以确保解析器是 XML 看到与您认为看到的 XML 相同。常见的 这里的错误包括:
- 正在传递给 XML 文档的文件名 解析器与您认为的不同。
- XML 的缓冲区脏了。确保它已经 在添加 XML. 之前清除
- 管道中先前阶段的较早程序 在生成的解析之前更改 XML 此错误消息。
您的具体问题
在您的特定情况下,您的 XML 似乎有多个根元素,因为 xsl:stylesheet
元素过早关闭(上述情况 #3)。
改变
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
至
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
解决您眼前的问题,并添加结束标记,
</xsl:stylesheet>
如果您的真实文档中不存在。
这也可能因为文件中的空格错误而出现