如何修复错误:文档中根元素后面的标记必须格式正确 [英] How to fix error: The markup in the document following the root element must be well-formed

查看:69
本文介绍了如何修复错误:文档中根元素后面的标记必须格式正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把我的代码放在 XML 验证网站上,它给了我这个错误:

<块引用>

第 8 行:4 文档中根元素后面的标记必须格式正确.

有问题的行是 <xsl:output method = "html" doctype-system = "about:legacy-compat"/>, line.

XML

<!-- 图 15.21:sorting.xsl --><xsl:stylesheet version = "1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/><!-- 写XML声明和DOCTYPE DTD信息-->*<xsl:output method = "html" doctype-system = "about:legacy-compat"/>*<!-- 匹配文档根目录--><xsl:template match="/">-<xsl:apply-templates/></html></xsl:模板>

解决方案

一般情况

<块引用>

文档中根元素后面的标记必须格式正确.

此错误表明您的 XML 在根元素之后有标记.为了格式良好,XML 必须有恰好一个根元素,并且在单个元素之后不能有进一步的标记根元素.

一个根元素示例(好)

<a/><b/><c/></r>

此错误的最常见来源是:

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

    <a/><b/><c/></r></r><!-- 不应该在这里-->

  2. 故意拥有多个根元素 (BAD):

    <b/><!-- 第二个根元素不应该在这里--><c/><!-- 第三个根元素不应该在这里-->

  3. 无意中拥有多个根元素 (BAD):

    <!-- 不应该自动关闭--><a/><b/><c/></r>

  4. 解析与您想象的不同的 XML (BAD):

    在提供给解析之前立即记录 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">

要解决您眼前的问题,并添加结束标记,

如果您的真实文档中尚不存在.

I put my code in the XML validation website and it gives me this error:

Line 8: 4 The markup in the document following the root element must be well-formed.

The line that is having an issue is the <xsl:output method = "html" doctype-system = "about:legacy-compat"/>, line.

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>

解决方案

General case

The markup in the document following the root element must be well-formed.

This error indicates that your XML has markup following the root element. In order to be well-formed, XML must have exactly one root element, and there can be no further markup following the single root element.

One root element example (GOOD)

<r>
  <a/>
  <b/>
  <c/>
</r>

The most common sources for this error are:

  1. Including stray or extra close tags (BAD):

    <r>
      <a/>
      <b/>
      <c/>
    </r>
    </r>  <!-- shouldn't be here -->
    

  2. Intentionally having multiple root elements (BAD):

    <a/>
    <b/>  <!-- second root element shouldn't be here -->
    <c/>  <!-- third root element shouldn't be here -->
    

  3. Unintentionally having multiple root elements (BAD):

    <r/>  <!-- shouldn't be self-closing -->
      <a/>
      <b/>
      <c/>
    </r>
    

  4. Parsing different XML than you think (BAD):

    Log the XML immediately before providing to the parse that's failing in order to make sure that the XML that the parser is seeing is the same as the XML you think it's seeing. Common errors here include:

    • The filename of the XML document being passed to the parser differs from what you believe it is.
    • The buffer of the XML being dirty. Make sure it's been cleared prior to adding your XML.
    • An earlier program from a prior stage in your pipeline changing the XML prior to the parsing that's yielding this error message.


Your particular problem

In your particular case, your XML appears to have multiple root elements because the xsl:stylesheet element is closed prematurely (case #3 above).

Change

            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>

to

            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

to fix your immediate problem, and add a closing tag,

</xsl:stylesheet>

if one does not already exist in your real document.

这篇关于如何修复错误:文档中根元素后面的标记必须格式正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆