XML Formatter and Beautifier
Beautify or minify XML with your choice of indentation and check that it is well-formed. This XML formatter keeps CDATA sections, comments, processing instructions and namespaces intact.
Press Ctrl+Enter (⌘+Enter on Mac) to run now.
Format and Beautify XML Online
XML still runs a large part of the software world: SOAP and payment APIs, RSS and sitemap feeds, Maven and .NET project files, Android layouts, SVG images and office documents. When it arrives as one unbroken line, finding a single element is painful. This XML formatter puts every element on its own line with consistent indentation, or minifies a pretty-printed file for transport.
Before formatting, the document is checked for well-formedness with your browser’s own XML parser, and any error is reported with its line, column and a code frame. CDATA sections, comments, processing instructions, the DOCTYPE and namespace prefixes are copied exactly, and the whole process runs in your browser without uploading the file.
How to format XML
- Paste the XML or open a file such as
.xml,.xsd,.svg,.rssor.config. - Check the status badge. “Well-formed XML” means the browser parser accepted the document; otherwise the error box shows where it failed.
- Choose Beautify or Minify, the indentation, and whether each attribute should get its own line.
- Tick “Remove comments” if you want a clean copy without
<!-- … -->blocks. - Copy or download the result as
formatted.xml.
How the XML formatter lays out a document
- Elements that contain other elements open on one line, their children are indented one level, and the closing tag gets its own line.
- Elements that contain only text stay on one line:
<name>Desk Lamp</name>. Line breaks and indentation left over from earlier formatting at the start and end of the text are removed; other whitespace is kept. - Mixed content, where text and elements are side by side as in
<note>Ships in <em>2–3</em> days</note>, is kept on one line exactly as written, because adding line breaks would change the text. xml:space="preserve"elements are copied untouched, including every space and line break inside them.- CDATA, comments, processing instructions and the DOCTYPE are copied character for character. Attribute values keep their quotes and entities, and only the spacing between attributes is normalised.
Minify uses the same rules but removes the whitespace between elements, so text content and preserved elements stay intact.
Well-formedness rules
Every XML parser must reject a document that breaks these rules from the XML 1.0 specification:
| Rule | Not well-formed | Well-formed |
|---|---|---|
| Exactly one root element | <a/><b/> | <r><a/><b/></r> |
| Tags close in reverse order | <b><i>x</b></i> | <b><i>x</i></b> |
| Names are case-sensitive | <Item>…</item> | <item>…</item> |
| Attribute values are quoted | <a id=1> | <a id="1"> |
| No duplicate attributes | <a x="1" x="2"> | <a x="1" y="2"> |
Escape & and < in text | Tom & Jerry | Tom & Jerry |
| Declaration comes first | A blank line before <?xml …?> | <?xml …?> on the first line |
| Prefixes are declared | <media:image/> alone | xmlns:media="…" on it or an ancestor |
No -- inside comments | <!-- a -- b --> | <!-- a - b --> |
Well-formed is not the same as valid: checking a document against a DTD or XML Schema (XSD) is a separate step that this tool does not perform.
Reading XML error messages
The browser parser decides whether the document is well-formed, so its original message is shown, for example Opening and ending tag mismatch in Chrome or mismatched tag in Firefox. Above it, the formatter adds a plain explanation and points to the line and column, with a few lines of context and a caret under the problem. The position usually marks the exact spot; for a missing closing tag it is often the end of the document or the next closing tag, so look slightly earlier as well. Undefined entities such as are a common surprise: XML only knows &, <, >, " and ' unless a DTD defines more, so write   instead.
Tips
- Use “One attribute per line” for long attribute lists, such as Android layouts, to get cleaner diffs.
- Store text with many
<and&characters, such as HTML snippets or code, in a CDATA section instead of escaping each character. - Need the data in another format? Convert it with XML to JSON, XML to CSV or XML to Excel.
- Working with JSON or YAML instead? Use the JSON formatter or the YAML validator.
Frequently Asked Questions
Common questions about formatting and checking XML.
Paste the XML into the input box and choose Beautify. The formatted XML appears on the right with the indentation you picked, ready to copy or download.
No. Only whitespace between elements changes. Text in mixed content, CDATA sections, comments, processing instructions and xml:space="preserve" elements are copied exactly.
A well-formed document follows the XML syntax rules: one root element, properly nested and closed tags, quoted attributes and escaped special characters. Every XML parser rejects documents that are not well-formed.
No. It checks well-formedness, which every XML document needs. Validation against a schema checks the allowed elements and types and needs the schema file and a validating parser.
XML defines only five named entities: &, <, >, " and '. Use the numeric reference   for a non-breaking space, or define the entity in a DTD.
Yes. Tick “Remove comments” and all <!-- … --> blocks are left out of the output. Comments inside xml:space="preserve" elements are kept.
Yes. They are XML documents, so any well-formed SVG, RSS, Atom, sitemap, XSD or XSLT file can be beautified or minified.
No. Parsing, checking and formatting happen in your browser, so the file never leaves your device.