XML Formatter
Paste XML to indent it neatly, check that it is well-formed, or minify it onto a single line. Errors are reported with a line and column number so you can find them quickly.
Your XML is checked and formatted as plain text. It is never rendered or run, and it stays on this device. The XML declaration, comments, CDATA sections and attribute quotes are kept as written.
How to Use the XML Formatter
- Paste your XML into the input box, or press Load example to try it out.
- Choose Beautify for indented output and pick 2 spaces, 4 spaces or tabs, or choose Minify to remove the whitespace between tags.
- If the XML is not well-formed, read the error message and fix the line and column it points to.
- Copy the result or download it as an .xml file.
Examples
Beautify
- Input
- <?xml version="1.0"?><note><to>Sam</to><from>Alex</from><body>Meeting at 10</body></note>
- Output
- <?xml version="1.0"?> <note> <to>Sam</to> <from>Alex</from> <body>Meeting at 10</body> </note>
Malformed XML
- Input
- <note><to>Sam</note>
- Output
- Line 1, column 14: Expected </to> to close the <to> tag, but found </note>.
About the XML Formatter
XML is still everywhere: sitemaps, RSS feeds, SOAP APIs, Android layouts, Office files, SVG images and configuration files. Machine-generated XML often arrives on a single line, which makes it hard to read or debug. Formatting puts each element on its own line and indents it by nesting level.
The formatter checks that your document is well-formed: every tag is closed in the right order, there is exactly one root element, attribute values are quoted and not repeated, and ampersands are escaped. It does not validate against a DTD or XML Schema (XSD), and it does not expand custom entities.
Elements that only contain text stay on one line, with whitespace trimmed from the start and end of the text. Elements marked xml:space="preserve" are left exactly as written, as are comments, CDATA sections, processing instructions and the XML declaration. In mixed content, where text and child elements sit side by side, whitespace around the text can change, so check the output if exact whitespace matters.
Your XML is processed as plain text in your browser. It is never rendered or executed, so scripts or external references inside it do nothing, and it is not sent to a Usevanta server.
Frequently Asked Questions
What does “well-formed” XML mean?
It follows XML’s basic syntax rules: one root element, every opening tag has a matching closing tag in the right order (or is self-closing like <br/>), attribute values are in quotes, and special characters such as & and < are escaped in text.
Does this validate my XML against a schema?
No. It checks well-formedness only. Checking that the document follows a particular DTD or XSD schema needs a schema-aware validator.
Will formatting change my data?
Beautify only changes whitespace between elements and trims whitespace at the start and end of text. Minify removes whitespace-only text between tags and keeps other text exactly as written. Content inside xml:space="preserve" elements is never changed.
Is the XML declaration kept?
Yes. A declaration such as <?xml version="1.0" encoding="UTF-8"?> is kept as written. It must be the very first thing in the document, and the formatter reports an error if it appears anywhere else.
Is it safe to paste XML from an unknown source?
Yes. The XML is only read as text and shown in a text box. It is never loaded as a document, rendered or run, so nothing inside it can execute.
Related Tools
All developer tools →Indent and tidy HTML markup so it is easy to read, without rendering it.
Format and validate JSON directly in your browser.
Beautify minified or messy CSS with one declaration per line.
Convert a JSON array of objects into a CSV file you can open in a spreadsheet.