Skip to content
Tooletto

XML Formatter

Format XML with proper nesting and indentation, or minify it. CDATA sections, comments and attributes containing angle brackets are preserved exactly, and unbalanced tags are reported.

  • Files never leave your device
  • Free, no signup
  • No watermarks
  • Works offline once loaded
Loading tool…

How to xml formatter

  1. 1

    Paste your XML

    A minified feed, a config file, a SOAP response — anything.

  2. 2

    Format or minify

    Indent for reading, or collapse for transport.

  3. 3

    Check for errors

    Mismatched and unclosed tags are named explicitly.

Where regex-based XML formatters actually break

A formatter built on regular expressions — inserting a newline before every `<` and indenting based on a running count of open tags — works passably on simple, hand-written XML and fails on real-world documents for reasons that are easy to overlook until they cause a corrupted file. A CDATA section, written as `<![CDATA[...]]>`, exists specifically to hold arbitrary text that might itself contain characters that look like tags, and a regex scanning for `<` has no way to know it should ignore everything between those markers rather than treating the contents as structure. Comments carry the same risk, and attribute values are worse still: an attribute like `note="a > b"` contains a literal `>` character that a naive scanner can mistake for the end of the tag, silently truncating it in the wrong place.

Correctly formatting XML means the scanner has to recognise these special regions — CDATA blocks, comments, processing instructions, DOCTYPE declarations, and quoted attribute values — before it looks for anything resembling tag structure, so their contents are carried through byte-for-byte rather than being reinterpreted as markup.

Validation here means well-formedness, not schema conformance

This tool checks that every tag is properly closed and correctly nested — the structural rules that make a document "well-formed" XML — and reports the specific mismatched or unclosed tag when that check fails. What it does not do is validate the document against a DTD or an XML Schema (XSD), which would additionally check whether the specific elements, attributes and their values conform to a particular document type's rules — whether a required attribute is present, whether an element appears in the right context, whether a value matches an expected data type. That is a genuinely different and more involved check requiring the schema document itself as an additional input, not something a general-purpose formatter can infer from the XML alone.

Why HTML needs a different tool entirely

Strict XHTML is valid XML and formats correctly here, but ordinary real-world HTML is not, for reasons built into the HTML specification itself: void elements like `<br>` and `<img>` are never closed and have no closing tag at all, several tags have optional closing tags that browsers infer automatically, and browsers tolerate malformed nesting that strict XML parsing would reject outright as an error. An XML-strict formatter applied to typical HTML would report errors on every well-formed, completely normal page, which is precisely why HTML gets a separate formatter built around an actual HTML parser that understands these HTML-specific rules rather than treating the document as strict XML.

Where XML still matters despite JSON's dominance

JSON has replaced XML as the default choice for new web APIs, but a great deal of infrastructure was built before that shift and still runs on it: SOAP web services, RSS and Atom feeds, SVG images (which are themselves XML), Office document formats internally, and a long tail of enterprise systems and configuration formats that predate JSON's popularity. Anyone integrating with one of these older or more formal systems still needs to read, debug and produce well-formed XML, which is precisely the audience a dedicated XML formatter continues to serve even as XML has receded from new API design.

Frequently asked questions

Does it validate my XML?

It checks that tags are balanced and correctly nested, and names the offending tag when they are not. It does not validate against a DTD or XSD schema — that requires the schema itself and is a different job.

Are CDATA sections and comments preserved?

Exactly as written. The scanner recognises `<![CDATA[…]]>`, comments, processing instructions and DOCTYPE declarations before it looks for tags, so markup inside them is never mistaken for structure — which is precisely where regex-based formatters corrupt files.

What about attributes containing < or >?

Handled. The scanner tracks quoting while reading a tag, so an attribute like `note="a > b"` does not terminate the tag early. This is a common failure in simple formatters.

Can I use it for HTML?

For strict XHTML, yes. Real-world HTML has void elements like `<br>` and `<img>` that never close, plus optional closing tags, so the HTML formatter is the right tool for that — it uses an actual HTML parser.

Common xml formatter tasks