草庐IT

xml - 如何修复错误 : The markup in the document following the root element must be well-formed

coder 2024-06-25 原文

我将我的代码放在 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>

此错误的最常见来源是:

  1. 包括杂散或额外的关闭标签 (BAD):

    <r>
      <a/>
      <b/>
      <c/>
    </r>
    </r>  <!-- shouldn't be here -->
    
  2. 故意拥有多个根元素(错误):

    <a/>
    <b/>  <!-- second root element shouldn't be here -->
    <c/>  <!-- third root element shouldn't be here -->
    
  3. 无意中有多个根元素(错误):

    <r/>  <!-- shouldn't be self-closing -->
      <a/>
      <b/>
      <c/>
    </r>
    
  4. 解析与您想象的不同的 XML(错误):

    在提供给解析之前立即记录 XML 失败以确保解析器的 XML seeing 与您认为它看到的 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 - 如何修复错误 : The markup in the document following the root element must be well-formed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355454/

有关xml - 如何修复错误 : The markup in the document following the root element must be well-formed的更多相关文章

随机推荐