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

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

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>  <!-- shouldnt be here -->
    
  2. Intentionally having multiple root elements (BAD):

    <a/>
    <b/>  <!-- second root element shouldnt be here -->
    <c/>  <!-- third root element shouldnt be here -->
    
  3. Unintentionally having multiple root elements (BAD):

    <r/>  <!-- shouldnt be self-closing -->
      <a/>
      <b/>
      <c/>
    </r>
    
  4. Parsing different XML than you think (BAD):

    Log the XML immediately before providing to the parse thats
    failing in order to make sure that the XML that the parser is
    seeing is the same as the XML you think its 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 its been
      cleared prior to adding your XML.
    • An earlier program from a prior stage in your pipeline
      changing the XML prior to the parsing thats 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.

this also may show up because of wrong spaces in this file

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

Leave a Reply

Your email address will not be published.