XMLBeautify XML Formatter

XML: Well-Formed vs Valid, and What the Checker Catches

XMLBeautify Guides · Updated 2026-10-30 · All guides

"Is this valid XML?" is two questions. The checker on this site answers only the first.

QuestionDefined byNeeds
Is it well-formed?The XML 1.0 syntax rulesJust the text
Is it valid?A DTD or a schema (XSD, RELAX NG)The document and the schema

A parser must refuse a document that is not well-formed. A document that is well-formed but invalid is a different failure that only a schema-aware validator reports.

What makes a document not well-formed

ErrorExampleWhy it is fatal
Mismatched or missing close tag<a><b></a>Nesting must be strict.
Two roots<a/><b/>A document has exactly one root element.
Unquoted attribute<a x=1/>HTML allows it; XML does not.
Duplicate attribute<a x="1" x="2"/>Attribute names are unique per element.
Bare ampersand<a>Tom & Jerry</a>& starts an entity reference; write &amp;.
Unknown entity<a>&nbsp;</a>Only &amp; &lt; &gt; &quot; &apos; and numeric references exist unless a DTD defines more.
< in an attribute value<a t="a<b"/>Must be &lt;.
Text outside the roothello <a/>Only comments, processing instructions and whitespace are allowed there.
Declaration not firstwhitespace before <?xml ...?>The declaration must be the first thing in the file.

The checker reports the first of these it meets, with line and column, then stops. Fix it and run again: later errors are often consequences of the first one.

The named-entity trap

&nbsp;, &copy; and &mdash; are HTML entities. Pasting HTML-flavoured text into an XML payload is the most common reason a feed or SOAP body is rejected. Use the numeric form (&#160;, &#169;, &#8212;) or the character itself in a UTF-8 document.

What passes here and can still fail

  • A required element is missing, or an element appears in the wrong order for the XSD.
  • An attribute has a value outside the schema's allowed set or type.
  • A namespace URI is wrong. To the checker soap:Envelope is just a name; a mismatched namespace is a schema or application error.

For those, use xmllint --noout --schema schema.xsd file.xml.

Developer Sponsor / Partner
Copied to clipboard!