我将我的代码放在 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 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>
此错误的最常见来源是:
包括杂散或额外的关闭标签 (BAD):
<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 seeing 与您认为它看到的 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 - 如何修复错误 : The markup in the document following the root element must be well-formed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355454/