What is an XML formatter?
XML (eXtensible Markup Language) is a structured text format for storing and transmitting data. Well-formed XML is hierarchical — every opening tag must have a closing tag, tags must be properly nested, and the document must have a single root element. An XML formatter takes compact or minified XML and adds indentation and line breaks to make the hierarchy visible, while an XML minifier does the reverse — stripping whitespace to reduce payload size. This tool validates the document before formatting using the browser's built-in DOMParser.
How to use this tool
- 1 Paste XML into the Input panel or click the sample button to load an example.
- 2 Choose Prettify to add indentation (2 spaces, 4 spaces, or tab), or Minify to strip whitespace.
- 3 Any structural errors (unclosed tags, bad nesting) are shown in the error bar below.
- 4 Copy the formatted result with the copy button on the Output panel header.
Frequently asked questions
How does validation work?
The tool uses the browser's built-in DOMParser with the application/xml MIME type. If parsing produces a <parsererror> node (which all browsers emit for malformed XML), the error message is extracted and displayed. This catches the most common errors: unclosed tags, bad attribute quoting, and illegal characters.
What is the difference between XML and HTML?
HTML is lenient — browsers fix unclosed tags and accept attribute values without quotes. XML is strict: every tag must be closed, attribute values must be quoted, and the document must have exactly one root element. XHTML is HTML that follows XML rules.
Does this handle XML namespaces?
Yes. Namespaced tags (e.g. <soap:Envelope xmlns:soap="…">) pass through correctly because the formatter operates at the text token level — it does not interpret namespace semantics.
Can I format very large XML files?
There is no hard size limit, but very large documents may be slow because DOMParser builds an in-memory DOM tree. For documents over a few MB, consider a dedicated CLI tool like xmllint.
Is my data sent anywhere?
No. Formatting and validation both use browser-native APIs. Your XML never leaves your device.