XML Formatter
Beautify or minify XML with exact line and column errors, keeping text-only elements, CDATA and mixed content intact.
This guide is not yet available in your language and is shown in English.
Tool guide
What this tool does
XML Formatter checks that a document is well-formed and then pretty-prints it with 2 spaces, 4 spaces or tabs, or minifies it to a single line. Text-only elements stay on one line, mixed content such as <p>Hello <b>world</b></p> is left exactly as written, and long attribute lists can be wrapped one per line.
XML arriving from APIs, build tools and exports is often a single enormous line, which makes it impossible to read or review. Worse, a missing closing tag or an unescaped ampersand somewhere in that line will make every XML parser reject the file, and the error message rarely says where.
This formatter first validates the document for well-formedness with fast-xml-parser and, when something is wrong, shows the line, the column and a code excerpt with a caret under the problem. Valid XML is rebuilt from a lightweight tree: each element starts on its own line, elements that contain only text or CDATA stay on one line, and mixed content, where text and child elements are interleaved, is printed exactly as written because whitespace there can be meaningful. Minify mode removes the whitespace between tags while keeping text untouched. All processing happens in your browser.
How to use XML Formatter
- Paste XML into XML input, open a file such as .xml, .svg, .xsd, .wsdl or .config, or click Sample.
- Choose the Mode: Beautify or Minify.
- For Beautify, pick the Indentation and whether attributes go on separate lines when an element has many.
- Toggle Self-close empty elements, Keep comments and Keep the XML declaration.
- If an error is shown, fix the reported line and column; the result updates as you type.
- Copy or download the result, or format several files at once and download them as a ZIP.
Tips for better results
- Wrapping attributes when an element has three or more makes SVG files and Maven or MSBuild project files far easier to diff in code review.
- Turn off Keep comments together with Minify to produce the smallest file for transmission.
- Entity references such as & and < are kept exactly as written, so the formatted document means the same as the original.
- Use XML to JSON next if you need to query the data in JavaScript.
Common use cases
- Reading a SOAP response or webhook payload while debugging an integration.
- Tidying sitemaps, RSS feeds and Android or .NET configuration files before committing them.
- Making exported SVG markup readable before editing it by hand.
- Minifying XML to reduce the size of payloads or embedded resources.
Common mistakes to avoid
- Pasting HTML: unclosed tags like <br> or <img> are fine in HTML but make XML invalid unless written as <br/>.
- Expecting XSD or DTD validation; the tool checks well-formedness only, not whether elements match a schema.
- Leaving a bare & in text or a URL; XML requires &, and the formatter will point to the exact column.
Frequently asked questions
Does formatting change the meaning of my XML?
Whitespace between elements is normally insignificant, and that is all Beautify changes. Text inside text-only elements is trimmed of surrounding spaces, and mixed content is kept exactly as written. If your format treats every space as data, keep the original file.
What does well-formed mean?
A well-formed document has a single root element, every start tag has a matching end tag in the right order, attribute values are quoted and special characters are escaped. It is a prerequisite for any XML parser to read the file.
Are CDATA sections and comments preserved?
Yes. CDATA sections are kept verbatim, and comments are kept unless you switch off Keep comments. Processing instructions and DOCTYPE declarations are also preserved.
Can it handle large files?
Yes. The formatter works in a single pass over the text and only updates after a pause in typing, so files of several megabytes format in well under a few seconds on a typical computer.
Feedback & suggestions
Help us improve XML Formatter. We read every message.