代码之家  ›  专栏  ›  技术社区  ›  Mereinid

如何修复错误:根元素后面的文档中的标记必须格式良好

  •  22
  • Mereinid  · 技术社区  · 7 年前

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

    有问题的线路是 <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>
    
    2 回复  |  直到 7 年前
        1
  •  42
  •   kjhughes    7 年前

    一般情况

    此错误表示XML在根元素后面有标记。 为了成为 well-formed must have exactly one root element ,并且在单个根元素之后不能有进一步的标记。

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

    1. <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 此处的错误包括:

      • 解析器与您所认为的不同。
      • 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>
    

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

        2
  •  0
  •   fady ahmed    4 年前