search

Home  >  Q&A  >  body text

How to fix the problem: Make sure the markup after the document root element is well-formed

<p>I put my code on the XML validation website and it gave me this error: </p> <blockquote> <p>Line 8: The document markup after the 4 root element must be well-formed. </p> </blockquote> <p>The problematic line is <code><xsl:output method = "html" doctype-system = "about:legacy-compat"/></code>. </p> <h2>XML</h2> <pre class="brush:php;toolbar:false;"><?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 element --> <xsl:template match="/"> -<html> <xsl:apply-templates/> </html> </xsl:template></pre> <p><br /></p>
P粉590428357P粉590428357468 days ago563

reply all(2)I'll reply

  • P粉761718546

    P粉7617185462023-08-22 16:50:01

    This may also occur due to incorrect whitespace in this file

    reply
    0
  • P粉186904731

    P粉1869047312023-08-22 13:13:03

    General situation

    This error means that your XML has tags after the root element. To comply with well-formed requirements, XML must have only one root element, and no other tags after the single root element .

    An example of a root element (correct)

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

    The most common causes of this error are:

    1. Contains extra closing tags (error):

      <r>
        <a/>
        <b/>
        <c/>
      </r>
      </r>  <!-- 不应该出现在这里 -->
    2. Intentionally having multiple root elements (error):

      <a/>
      <b/>  <!-- 第二个根元素不应该出现在这里 -->
      <c/>  <!-- 第三个根元素不应该出现在这里 -->
    3. Inadvertently having multiple root elements (error):

      <r/>  <!-- 不应该是自闭合的 -->
        <a/>
        <b/>
        <c/>
      </r>
    4. The parsed XML is different than you think (wrong):

      Log the XML immediately before feeding it to the parser to ensure that the XML the parser sees is the same XML you think it is. Common mistakes here include:

      • The XML document passed to the parser has a different filename than you think.
      • XML buffer is dirty. Make sure it is cleared before adding the XML.
      • A program at a previous stage in the pipeline changed the XML before it was parsed, causing this error message.

    Your specific question

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

    Will

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

    change to

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

    to address your immediate question and add a closing tag

    </xsl:stylesheet>

    If it doesn't exist yet in your actual document.

    reply
    0
  • Cancelreply