About the XML Formatter
The XML Formatter takes raw or minified XML and returns it either neatly indented or compressed. It parses the document first, so malformed XML is flagged rather than formatted incorrectly.
How it works
The input is parsed with the browser's DOMParser as XML. If the parser reports an error, the output shows "Error: Invalid XML". Otherwise the root element is serialized back to text, which normalizes the markup.
In Beautify mode a line break is inserted between every pair of adjacent tags, and each line is indented by two spaces per nesting level. In Minify mode any whitespace between a closing > and the next < is removed. Because only the root element is serialized, an XML declaration such as <?xml version="1.0"?> and comments outside the root are not included in the output.
How to use
- 1
Choose Beautify or Minify.
- 2
Paste your XML into the input box.
- 3
Read the result in the output panel.
- 4
Click Copy to copy the formatted XML.
Worked examples
Beautify
A one-line catalog.
Minify
Indented XML to a single line.
Frequently asked questions
Does this validate my XML as well as format it?+
It checks that the XML is well-formed and shows "Error: Invalid XML" if not. For the parser's specific message, use the XML Validator.
Can I use this for RSS feeds or sitemaps?+
Yes. Any well-formed XML document works, including feeds, sitemaps, and configuration files.
Why is my <?xml ... ?> declaration missing?+
The formatter serializes only the root element, so the declaration and any comments outside the root are left out. Add the declaration back by hand if needed.
What indentation does it use?+
Two spaces per level. The indent size cannot be changed.