Tools
EN

XML Formatter and Validator

Paste XML to pretty print it with 2 or 4 spaces or tabs, minify it, or check that it is well-formed. Errors are shown with line, column and a clear explanation, and comments, CDATA sections and text stay exactly as written.

Private: your data is processed in your browser and never uploaded.

How to format XML

  1. Paste your XML, drop an .xml file onto the editor or load it from a URL.
  2. Click Format (or press Ctrl+Enter) and choose the indentation. Minify removes the whitespace between elements.
  3. If the XML is not well-formed, the error box shows the line, the column and the cause, and the line is highlighted. Fix it, then copy or download the result.

What the XML formatter does

Common reasons XML is not well-formed

ProblemExampleFix
Tags in the wrong order<b><i>text</b></i>Close the inner element first: </i></b>
Unescaped ampersandAT&TWrite AT&amp;T
Unescaped less-than signa < bWrite a &lt; b or use CDATA
Attribute without quotes<item id=7><item id="7">
Two root elements<a/><b/>Wrap them in one parent element
HTML entities&nbsp;, &copy;Use &#160;, &#169; or declare them in a DTD

Format XML on the command line and in code

Why use Online XML Formatter?

Frequently asked questions

Is my XML uploaded to a server?

No. Formatting and validation run in your browser. Only Load URL fetches the file through our server, because browsers block most direct downloads from other sites; the content is passed straight to you and not stored.

Does formatting change my data?

No. Only the whitespace between elements changes. Text, attribute values, entities, CDATA sections and comments stay exactly as written, and elements with mixed content are left untouched.

What is the difference between well-formed and valid XML?

Well-formed XML follows the syntax rules: one root element, properly nested and closed tags, quoted attribute values and escaped special characters. Valid XML additionally matches a schema (XSD) or a DTD. This tool checks well-formedness.

Can I format very large XML files?

Yes. A 2.6 MB file with 20,000 records is parsed and formatted in a fraction of a second, and the editor draws line numbers only for the visible lines, so it stays responsive.