XML Formatter and Validator
Part of Text tools: See all Text tools.
What is XML Formatter?
XML Formatter turns minified or badly indented XML into a clean, nested layout with one element per line and the indent you pick (2 spaces, 4 spaces or a tab). Minify does the opposite and removes the whitespace between tags. Check only tells you whether the document is well-formed and, if not, the line and column of the first error. The XML declaration, DOCTYPE, namespace prefixes, comments, CDATA sections and processing instructions are kept, and elements that contain text are left on one line so their text is not changed.
How to use XML Formatter
- Paste your XML into the box, or use Open a file to load an .xml, .xsd, .svg, RSS or config file from your device. The file is read in your browser.
- Choose the indent: 2 spaces, 4 spaces or a tab. Tick Remove comments if you want the output without <!-- comments -->.
- Click Format XML for a readable layout, Minify (one line) for a compact version, or Check only to test well-formedness without changing anything.
- Read the status line. It shows the root element and element count, or the line, column and reason for the first error. Then use Copy result or Download .xml.
Why use this tool?
XML from SOAP services, RSS feeds, sitemaps, Maven or .NET project files, Android layouts and data exports often arrives as one long line, which makes a missing closing tag or a value in the wrong element hard to spot. Putting each element on its own line shows the nesting at a glance, gives clean line-by-line diffs in code review, and the error position points you straight at the tag that breaks a parser.
XML Formatter — In-Depth Guide
Well-formed XML follows a few strict rules: there is exactly one root element, every opening tag has a matching closing tag or is self-closing, elements close in the reverse order they opened, attribute values are quoted, and the characters < and & inside text are written as < and &. Element names are case-sensitive, so <Item> and </item> do not match. A single broken rule stops a parser from reading the whole file, which is why the error line and column are the first thing to look at.
The most common errors have quick fixes. "Opening and ending tag mismatch" or "mismatched tag" means an element was closed in the wrong order or a closing tag is misspelled. "Extra content at the end of the document" or "junk after document element" means two top-level elements, so wrap them in one parent. An error at an & usually means a raw ampersand in a URL or a company name; write it as &. Text or a blank line before <?xml ... ?> also breaks a document, because the declaration must come first.
Pretty-printing XML is safe for most data formats, but whitespace can matter in documents that mix text and markup, such as XHTML, DocBook or Word's XML. This formatter leaves any element that holds text on one line and respects xml:space="preserve", so paragraphs are not broken up. If you need byte-for-byte output, for example for an XML signature, do not reformat the signed part at all, because any change to whitespace breaks the signature.
Tip: format two versions of a config or API response with the same indent, then paste both into Text Diff to see exactly which elements changed. To move data between formats, use XML to JSON or JSON to XML, and use the JSON Formatter or YAML Formatter when the data is already in those formats.
Frequently asked questions
- Does it validate my XML?
- It checks that the XML is well-formed: one root element, every tag closed and correctly nested, quoted attributes, no duplicate attributes and special characters escaped. If something is wrong, the status line shows the line, the column and the parser's reason. It does not validate against an XSD or DTD schema, so it cannot tell you that a required element is missing; use a schema validator for that.
- Does formatting change my data?
- Only the whitespace between tags changes. Element and attribute names, attribute values, text, CDATA and comments are kept. A few things are written in an equivalent form: an empty element such as <item></item> is written as <item/>, attributes use double quotes, and character references such as © are written as the character itself. Any XML parser reads the result the same way.
- What happens to text mixed with tags?
- If an element contains text, for example <p>Hello <b>world</b></p>, that whole element stays on one line exactly as written, because adding line breaks inside it would change the text. Elements with xml:space="preserve" are also left untouched. Only elements that contain other elements and whitespace are re-indented.
- Are namespaces, CDATA, comments and the XML declaration kept?
- Yes. Namespace prefixes and xmlns attributes stay as you wrote them, CDATA sections and processing instructions such as <?xml-stylesheet?> are kept, and the <?xml version ... ?> declaration and any DOCTYPE are copied from your input. Comments are kept unless you tick Remove comments.
- What does Minify do?
- It removes the line breaks and indentation between tags so the XML fits on one line, which is useful for API payloads, config values and test fixtures. Text inside elements is not trimmed, so the data stays the same. Tick Remove comments as well for the smallest output.
- How large a file can it handle?
- There is no fixed limit, because everything runs on your device. Very large files, such as exports of tens of megabytes, can make the page slow or run out of memory, depending on your browser and device.
- Is my XML uploaded?
- No. Parsing and formatting use your browser's built-in XML parser, and an opened file is read locally. Nothing is sent to our server, so you can format internal configs and API responses.
Also try
Related tools that work well with this one: