XML Formatter
Understand XML Formatter
This formatter indents XML by nesting depth, collapses it back to one line, and reports the first place the document is not well-formed.
How it works
The document is handed to the browser's own XML parser, so the well-formedness check is the same one the browser applies: exactly one root element, every tag closed, every attribute quoted, and a bare & rejected because it begins an entity reference. If the parser reports an error the tool surfaces it; otherwise the document is serialized again and re-indented one tag per line.
When to use it
- Reading a SOAP request or response captured off the wire.
- Untangling a deeply nested pom.xml, an Android layout, or an RSS feed.
- Finding which tag is unclosed in a document a parser rejected.
- Minifying XML before putting it in a test fixture or a header value.
Watch out for
- Well-formed is not valid. This checks syntax and does not check the document against a DTD or an XSD, so a structurally perfect file can still be rejected by the service that expects a schema.
- Whitespace between elements is discarded during re-indentation. In mixed content — text and elements in the same node, as in a paragraph containing a bold run — that whitespace is rendered output, so reformatting prose-carrying XML can change what it means. The same applies to anything marked xml:space="preserve".
- HTML is not XML. Unclosed tags such as <br> and <img>, and unquoted attributes, are legal HTML and errors here.
- XML is case-sensitive, so <Item> and <item> are different elements — a routine surprise for anyone arriving from HTML.
Not the right tool for: Formatting HTML. Use the HTML formatter, which knows about void elements and inline elements.
Frequently Asked Questions
How do I fix "unexpected token" errors in XML?
Common XML errors: unclosed tags (<br> must be <br/>), unquoted attributes (id=foo must be id="foo"), & that should be &, and multiple root elements. The formatter highlights exactly which line and character caused the error.
What is the difference between well-formed and valid XML?
Well-formed XML follows syntax rules (proper nesting, single root, quoted attributes). Valid XML additionally conforms to a DTD or XSD schema. This tool checks well-formedness — it does not validate against a schema.
Can I use this to format RSS or Atom feeds?
Yes. RSS and Atom are XML formats and will parse and format correctly. This is useful for debugging feed readers or inspecting malformed feed content.
How to Use XML Formatter
- Paste or type your input in the input area above.
- The tool processes your input automatically or click Run.
- Copy or download the result using the action buttons.
- Use Ctrl+Enter to run quickly from the keyboard.