加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 如何修复错误:根元素后面的文档中的标记必须格式正确

发布时间:2020-12-16 23:26:08 所属栏目:百科 来源:网络整理
导读:我把我的代码放在 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”/gt ;,line. XML ?xml ve
我把我的代码放在 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”/&gt ;,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>

解决方法

一般情况

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

此错误表示您的XML在根元素后面有标记.
要成为well-formed,XML must have exactly one root element,并且单个根元素后面不能再有标记.

一个根元素示例(GOOD)

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

此错误的最常见来源是:

>包括迷路或额外关闭标签(BAD):

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

>故意有多个根元素(BAD):

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

>无意中有多个根元素(BAD):

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

>解析不同于您的XML(BAD):

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读