How to format and validate XML
XML still runs the plumbing of the internet: SOAP APIs, RSS feeds, sitemaps, SVG, Android layouts, Maven configs, Office documents. It is verbose by design and miserable to read unformatted — one long line of tags where structure should be.
Unlike lenient HTML, XML is strict: every tag closes, attributes quote, one root element, correct nesting. A real tokenizer matters here — naive formatters mangle comments, CDATA sections and DOCTYPE declarations. This one parses the actual syntax, and validation reports errors with line and column.
Open the free XML Formatter — no signup, runs entirely in your browser.
How to use it
- Paste your XML document into the editor.
- Choose Beautify with your indentation, Minify, or Validate only.
- Validation errors show line and column so you jump straight to the problem.
Why this one
- A real XML tokenizer — attributes, comments, CDATA, DOCTYPE and processing instructions handled correctly.
- Beautify with 2 spaces, 4 spaces or tabs.
- Validation checks nesting and document shape, not just tag matching.
- Line-and-column error reporting for fast fixes.
Frequently asked questions
What is the difference between XML and HTML?
HTML is forgiving: browsers repair broken markup silently. XML is strict: a single unclosed tag or unquoted attribute invalidates the whole document. That strictness is why validation actually means something for XML.
What makes XML invalid?
Unclosed or crossed tags, multiple root elements, unquoted attributes, stray text outside the root, or illegal characters. The validator reports the first problem with its exact position.
Are CDATA sections and comments preserved?
Yes. The formatter understands CDATA, comments, DOCTYPE and processing instructions as first-class syntax — they are kept intact, not treated as ordinary text.