How to Format and Validate XML

By Ramanathan Aug 9, 2026 1 min read XML Formatter & Validator

XML is still everywhere — config files, SOAP APIs, RSS feeds, office document formats. When a chunk of XML won't parse, it's almost always a well-formedness rule being broken. Here's what to check.

Well-formed vs valid

Two different things:

  • Well-formed — the XML follows the basic syntax rules below. A parser can read it.
  • Valid — the XML also conforms to a schema (DTD or XSD) that defines which elements and attributes are allowed.

Most everyday errors are about being well-formed; schema validation is a separate, stricter step.

The rules parsers enforce

  • One root element wraps the whole document.
  • Every tag closes<item>…</item>, or self-close with <item/>.
  • Tags nest, never overlap<a><b></b></a>, not <a><b></a></b>.
  • Attribute values are quotedid="1", never id=1.
  • Case matters<Item> and <item> are different elements, and a closing tag must match its opening tag exactly.
  • Special characters are escaped&lt;, &gt;, &amp; for <, >, &.

Why formatting helps

Minified or hand-edited XML hides its structure. Indenting it so each nested element lines up makes a missing or mismatched tag jump out immediately — which is usually how you find the one line breaking the parse.

Related

Working with data formats more broadly? See JSON vs XML vs YAML vs CSV for when XML is the right choice.

Try it

Paste XML to format and validate it — errors are reported clearly so you can fix them fast, all in your browser with nothing uploaded.

About the author

Ramanathan · Software Engineer & Solutions Architect

I'm a Software Engineer and Solutions Architect with 20+ years of experience building enterprise applications across BFSI, Healthcare, Retail, Manufacturing, and Industrial Automation. I've spent those two decades living in JSON, tokens, regexes, and config files — so I built the fast, private, no-login developer tools I always wanted to reach for myself.

Last updated: Aug 9, 2026