XML Formatter & Beautifier
Paste XML to beautify (pretty-print with clean indentation), minify (collapse to one line), or validate (check it is well-formed). Comments, CDATA and attributes are preserved — everything runs in your browser and nothing is uploaded.
How the XML formatter works
The tool reads your XML character by character and splits it into tokens — start tags, end tags, self-closing tags, text, comments, CDATA sections, processing instructions and the declaration. It then re-emits those tokens with one level of indentation added for every open element and removed when it closes, so the nesting depth is shown by how far each line is indented. Because it works on tokens rather than discarding anything, nothing in your document is lost: attributes, comments and the raw contents of CDATA sections come through exactly as you typed them. Minify does the reverse — it drops the whitespace between tags so the document collapses to a single compact line, while leaving text and CDATA content untouched.
Beautify vs. minify vs. validate
| Action | What it does | Use it when… |
|---|---|---|
| Beautify | Adds indentation and line breaks (2/4-space or tab). | You need to read or debug XML that arrived minified or on one line. |
| Minify | Removes whitespace between tags; keeps text & CDATA. | You want the smallest file to send over the network or store. |
| Validate | Checks well-formedness and reports the exact error. | A parser is rejecting your XML and you need to find why. |
Every time you edit the input or switch action the tool also re-checks well-formedness, so the status line under the boxes always tells you whether the document parses and, if not, where it fails.
XML syntax reference
| Part | Example | Notes |
|---|---|---|
| Prolog / declaration | <?xml version="1.0" encoding="UTF-8"?> | Optional first line naming the XML version and character encoding. |
| Element | <title>Midnight Rain</title> | A start tag, content, and a matching end tag. Every start tag must be closed. |
| Empty element | <br/> | A self-closing tag — shorthand for an element with no content. |
| Attribute | <book id="bk101"> | A name="value" pair on a start tag; the value must be quoted (single or double). |
| Comment | <!-- notes here --> | Ignored by parsers; kept verbatim by this formatter. |
| CDATA section | <![CDATA[ if (a < b) … ]]> | Raw text that may contain < and & without escaping — kept exactly as-is. |
| Processing instruction | <?xml-stylesheet href="s.xsl"?> | An instruction for the application processing the document. |
| Entity reference | < > & " ' | Escapes for the five reserved characters < > & " and ’. |
Well-formed vs. valid XML
This tool checks that your XML is well-formed — it obeys the basic syntax rules: a single root element, every start tag closed, tags nested correctly, attribute values quoted, and the five reserved characters escaped (or wrapped in CDATA). That is different from being valid, which additionally means the document conforms to a specific schema (a DTD or an XSD) that defines exactly which elements and attributes are allowed and in what order. Well-formed is the prerequisite: XML must be well-formed before it can be checked against a schema. If you only need your file to parse cleanly, well-formedness is what you are after — and that is what the status line reports here.
Common uses
- Reading a minified API response (SOAP, RSS/Atom feeds, sitemaps) that came back on one line.
- Cleaning up configuration files (
pom.xml, Android layouts,web.xml,.svg) before a diff or code review. - Shrinking an XML payload before sending it, then expanding it again to debug.
- Finding an unclosed or mismatched tag that a stricter parser is rejecting.
Privacy
The formatter is entirely client-side. Your XML is parsed and re-indented in your own browser, is never sent to a server, and is not stored or logged — so it is safe to use with private configuration and API data, and it works offline once the page has loaded.
Frequently asked questions
- What does an XML formatter (beautifier) do?
- It re-indents XML so the nested structure is easy to read. Minified or single-line XML — the way APIs and config files often store it — is expanded onto separate lines with each child element indented under its parent. This tool does not change the data: element names, attributes, text content, comments and CDATA sections are all preserved exactly; only the whitespace between tags is rewritten. You can choose 2-space, 4-space or tab indentation.
- What is the difference between beautifying, minifying and validating?
- Beautify (pretty-print) adds indentation and line breaks so a human can read the structure. Minify strips all the whitespace between tags to make the file as small as possible for transmission or storage — text inside elements and CDATA is kept intact. Validate checks that the document is well-formed: every tag is closed, tags nest correctly, attribute values are quoted and there is a single root element. This tool can do all three, and it reports the exact well-formedness error if there is one.
- Does it check that my XML is well-formed?
- Yes. It parses your input with the browser’s built-in XML parser and shows a green “well-formed” status or the exact error (with the line and column where parsing failed) — for example an unclosed tag, a mismatched end tag or an unquoted attribute. Note this is a well-formedness check, not schema validation: it confirms the XML follows the syntax rules of the language, but it does not validate against a DTD or XSD, so it will not tell you whether your elements match a particular schema.
- Are comments, CDATA and attributes kept?
- Yes. The formatter tokenises the document rather than throwing parts away, so XML comments (<!-- … -->), CDATA sections (<![CDATA[ … ]]>), processing instructions, the <?xml …?> declaration and DOCTYPE lines are all preserved verbatim. Attribute order and values are untouched, and the raw text inside CDATA — including any < or & characters — is copied through exactly, because that is the whole point of a CDATA section.
- Is my data uploaded anywhere?
- No. The entire tool is plain JavaScript running in your browser. Your XML never leaves your device — there is no upload, no server round-trip and nothing is stored or logged. That makes it safe for configuration files, API payloads and other sensitive documents, and it keeps working offline once the page has loaded.
- How do I fix an "unclosed tag" or "mismatched tag" error?
- Those errors mean a start tag has no matching end tag, or the end tag’s name does not match the nearest open element. Read the reported line and column, then check that every <tag> has a corresponding </tag> and that tags close in the reverse order they opened — <a><b></b></a>, never <a><b></a></b>. Also make sure the document has exactly one top-level (root) element and that every attribute value is wrapped in quotes. Beautifying valid XML makes these structural mistakes much easier to spot.