InTab

XML Formatter

Beautify, minify and validate XML documents.

Formatters: Pretty-print, minify, validate and compare. It runs in your browser, so nothing you enter is uploaded.

What it does

The XML Formatter indents XML so its structure is easy to read, compresses it to save space, or turns it into an escaped string. It checks that the document is well-formed as it goes and shows how many elements it contains, so you notice an unclosed tag before a parser rejects the file.

Broken XML is repaired rather than rejected: tags left open are closed, stray closing tags and a tag cut off at the end are removed, attribute values are quoted, a bare & or < is escaped, and log text around the XML is dropped. The status bar lists each fix, and Auto-fix writes the repaired XML back into the editor.

How to use it

  1. Paste XML into the Input pane, open a file, or click Load sample.
  2. Choose Beautify to indent, Minify to remove whitespace between tags, or Stringify to get an escaped string for code.
  3. Pick 2 spaces, 4 spaces or Tab, and untick Keep comments if you want comments removed.
  4. Copy or download the result. Single and Split switch between one pane and input and output side by side.

Example

<catalog><book id="bk101"><title>XML Developer's Guide</title><price currency="USD">44.95</price></book></catalog>

Beautified with 2 spaces:

<catalog>
  <book id="bk101">
    <title>XML Developer's Guide</title>
    <price currency="USD">44.95</price>
  </book>
</catalog>

Good to know

  • Well-formed means every tag is closed and nested correctly. It does not check an XSD or DTD schema.
  • CDATA sections and the XML declaration (<?xml …?>) are kept as they are.
  • Minifying never changes the text inside elements, only the whitespace between tags.

FAQ

Can it format HTML? Strict XHTML works. For everyday HTML with unclosed tags such as <br> use the HTML Formatter.

How do I turn XML into JSON or into classes? Use the XML to JSON converter, or XML to Code for C#, Java, Go and TypeScript classes.

Guides

More Formatters tools

  • JSON Formatter: Beautify, minify, validate and sort JSON. Handles escaped/stringified JSON.
  • SQL Formatter: Format SQL for MySQL, PostgreSQL, T-SQL, SQLite and more.
  • Diff Finder: Compare two texts or JSON documents line by line or word by word.
  • Text Diff Checker: Paste two versions of a text and see exactly which words changed.
  • JSON Validator: Check JSON is valid and see the exact line, column and a fix hint when it is not.
  • JavaScript Formatter: Beautify minified or messy JavaScript with your choice of indentation.
  • JavaScript Minifier: Minify JavaScript with Terser: compress, shorten names and see the size saved.
  • HTML Formatter: Indent and tidy HTML, or minify it for production.
  • CSS Formatter: Beautify CSS with one rule per block and consistent indentation.
  • CSS Minifier: Minify CSS with CSSO: remove whitespace, merge rules and shorten values.
  • YAML Formatter: Validate and re-indent YAML, keeping comments, with optional key sorting.