相关文章推荐
玩篮球的茴香  ·  java mongo 忽略字段 ...·  11 月前    · 
眼睛小的青蛙  ·  「 ...·  1 年前    · 
性感的桔子  ·  特别企划 | ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How to fix error: The markup in the document following the root element must be well-formed

Ask Question

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

<?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>

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)

The most common sources for this error are:

  • Including stray or extra close tags (BAD):

    </r> <!-- shouldn't be here -->
  • Intentionally having multiple root elements (BAD):

    <b/> <!-- second root element shouldn't be here --> <c/> <!-- third root element shouldn't be here -->
  • Unintentionally having multiple root elements (BAD):

    <r/>  <!-- shouldn't be self-closing -->
    
  • 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"/>
    
                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.

    Copy that, KJH, I had the closing tag down on about line 18. Thank you for your time and timely response. – Mereinid Sep 22, 2017 at 1:51 HA, I jinxed my self. And I will accept the above answer. Question; I ran the entire thing through the XML Validation site, I received no errors. I loaded it onto my schools webserver to render the page in Chrome so I could turn it in for my homework this week. Chome is giving me an error on line 8 also; This page contains the following errors: error on line 8 at column 3: Extra content at the end of the document. Is the extra content at the end of the document referring to that particular line or then end of the entire document? – Mereinid Sep 22, 2017 at 1:58 @Mereinid: Please read Well-formed vs Valid XML and understand that neither being well-formed nor valid implies correctness of your XSLT. See also Running XSLT in a Web Browser. Beyond this answer and those two answers, you'll have to post another question if you're still having problems. Comments aren't meant for new questions -- just clarifications. Thank you. – kjhughes Sep 22, 2017 at 2:04 Very detailed use-cases, thanks @kjhughes. I may add my 2 cents, sometimes you may have some well formed looking XML giving you the same error as OP's upon parsing. One possible reason is the XML might contain invisible characters such as but not limited to ZERO WIDTH SPACE (U+200B) or ZERO WIDTH NO BREAK SPACE (U+FEFF). This thread gives a trick to spot and remove them. – Attila Oct 31, 2018 at 12:27 I saw this error when an opening html tag got copy/pasta'ed (deleted). The xml parser was throwing an error on the line of the opening body tag. – Sean Anderson Apr 5, 2022 at 1:51 An example of this error arising due to "wrong spaces in this file" would make your answer immensely more useful. As it stands, it's not helpful. – kjhughes Jul 14, 2022 at 20:57

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

    DrawerLayout - The markup in the document following the root element must be well-formed See more linked questions
  •