How to use it
- Paste XML into the input box, open an .xml file from your device, or try the example.
- Choose Format to indent the document or Minify to remove the whitespace between tags.
- Pick 2 spaces, 4 spaces or tabs for indentation, and decide whether comments are kept.
- If the XML is not well-formed, fix the problem at the reported line and column. Otherwise copy or download the result.
How it works
The formatter reads the XML with its own parser that understands elements, attributes in single or double quotes, comments, CDATA sections, processing instructions such as the <?xml?> declaration, and DOCTYPE declarations including an internal subset. It checks the rules for well-formed XML: every opened element must be closed in the right order, there must be exactly one root element, attribute names must not repeat, attribute values must not contain <, and every & must start an entity reference.
When formatting, each element, comment and CDATA section goes on its own line. An element that contains only text stays on one line, for example <title>Midnight Rain</title>. Leading and trailing spaces inside text nodes are removed and whitespace-only text between tags is dropped. If whitespace matters in part of a document, mark that element with xml:space="preserve" and it is copied exactly as written.
Minifying removes the whitespace-only text between tags and, if you untick “Keep comments”, the comments. Text content and CDATA are not changed. Entity references such as & are kept as written, never expanded.
This is a well-formedness check, not validation against a DTD or XML Schema: it does not know which elements a particular format allows. Namespaced names such as xs:element are treated as plain names.
Examples
Reading a one-line API response
A SOAP or RSS response arrives as a single 4,000-character line. Formatting it with 2-space indentation shows the nesting of envelope, body and items so you can find the field you need.
Finding a broken tag in a sitemap
A sitemap.xml fails to load in Search Console. Pasting it shows “Line 214, column 5: Closing tag </urlset> does not match the open element <url>”, which points to the entry that is missing its </url>.
Shrinking an SVG or config file
Minify with “Keep comments” unticked to remove indentation and editor comments from an SVG icon before embedding it in a page.
Frequently asked questions
Does it validate against a schema (XSD) or DTD?
No. It checks that the document is well-formed: correct nesting, one root element, quoted attributes, no duplicate attributes and valid entity references. Whether the elements are allowed by a particular schema is not checked.
Will formatting change my data?
Formatting removes whitespace between tags and trims spaces at the start and end of text nodes. For most data formats that whitespace has no meaning. Where it does, add xml:space="preserve" to the element and its content is copied unchanged. Minify leaves text content exactly as it was.
Can I format HTML with this tool?
Only if it is XHTML. Ordinary HTML allows tags such as <br> without a closing slash, which XML rejects. Use the HTML formatter for regular HTML.
Is there a size limit?
There is no fixed limit, but very large files (tens of megabytes) are processed on your device's memory and may make the page slow. Files opened with “Open file” can be up to 20 MB.
Privacy
Your XML is parsed and formatted only in your browser. Nothing is uploaded, stored or included in analytics.