XML Formatter
Format and beautify XML documents.
About the XML Formatter
Paste minified XML and get an indented tree back, or collapse a formatted document to a single line with Minify. The XML declaration, DOCTYPE, comments and CDATA sections all survive, and namespace prefixes are left exactly as written, so SOAP envelopes, RSS feeds, Android layouts and Maven POMs all format cleanly. Everything runs in your browser, so an internal service payload never leaves your machine.
How to use the XML Formatter
- Paste your XML into the input panel, or press Sample to load an example.
- Pick 2 spaces or 4 spaces from the Indent selector.
- Press Beautify to indent the document, or Minify to collapse it to one line.
- Read the error message if the document is rejected, fix it, and run it again.
- Press Copy for the clipboard, or Download to save formatted.xml.
Frequently asked questions
- What does the formatted XML look like?
- One element per line, children indented by the width you chose, and self-closing tags left in that form. The sample catalogue comes back with <catalog> on the first line, <book id="1"> indented two spaces and <title>Clean Code</title> four. Attributes stay on the element line however many there are, so a tag carrying ten of them is not wrapped.
- Why does my XML fail to format?
- There are only two rejections. More than one top-level element reports "Found multiple root nodes". Anything the parser cannot read at all reports "Failed to parse XML", which covers an empty box, text that is not markup, and a stray < inside content that was never escaped as <.
- Does it repair broken markup?
- Quietly, yes, which is worth knowing before trusting the output. An unclosed tag is closed for you, so <a><b></a> comes back as <a><b></b></a>, and a mismatched closing tag is rewritten, so <a><b></c></a> returns the same repaired document. A bare & is passed straight through rather than flagged. None of this raises an error, so treat the tool as a formatter and not a validator.
- Does formatting change the document?
- It changes whitespace between elements only. Mixed content is left alone, so <p>Hello <b>world</b> now</p> stays on one line, and a text node that is only whitespace keeps it, so <a> spaced </a> is untouched. Where a consumer treats inter-element whitespace as significant, indenting is still a change to the bytes.
- Can I convert the result to JSON?
- Yes. The XML to JSON tool parses the same document and emits an equivalent JSON structure, mapping attributes and text nodes to keys.