XML Formatter

How to use

Cleans up messy XML by adding proper indentation, or shrinks it into a single line to save space. It also checks whether the XML is well-formed and points out parsing errors. Paste your XML, choose Format or Minify, and copy the result.

DeveloperLocal only
Indent:
Input XML
Output
Result will appear here...
When to use this
  • Making a single-line SOAP API response readable enough to debug
  • Reformatting a configuration file before committing it for code review
  • Checking that an XML document is well-formed before feeding it into a parser
  • Minifying an XML payload to shave bytes off a request before sending it

Where XML whitespace is decoration and where it is content

Reformatting XML is not always safe, and the reason is that XML has no general rule about whitespace being insignificant. In mixed content, an element containing both text and child elements, the spaces between them are part of the document, and adding indentation changes the data. Whether whitespace matters is decided by the schema, not by the parser, which is why an XML formatter should be applied to configuration and data documents and treated carefully around anything document-oriented, such as XHTML fragments or DocBook.

The xml:space="preserve" attribute exists to mark the regions where this matters explicitly, and content inside a CDATA section is likewise off-limits: it is verbatim by definition. A formatter that ignores either will produce a well-formed document that means something different from the one it was given. That failure is quiet, which is what makes it worth knowing about before reformatting a file you did not write.

Formatting also serves as a well-formedness check, and the distinction between well-formed and valid is worth keeping. Well-formed means the syntax parses: every tag closed, attributes quoted, one root element, entities properly escaped. Valid means it also conforms to a schema: the right elements in the right order with the right types. A formatter answers the first question and reports precisely where parsing failed. Only a schema validator answers the second, and a document can be flawlessly well-formed and completely wrong for its purpose.

Free and private. Everything runs on your own device, with no account and no uploads.

Integration developers working with SOAP APIs or configuration files often receive XML crammed onto a single line, making it nearly impossible to read. This formatter adds proper indentation to messy XML, or minifies it down to one line to save space, while also checking that the document is well-formed and pointing out where parsing errors occur, all without installing an IDE plugin.

No, it only checks that the XML is well-formed (properly nested and closed tags), it does not validate against an XSD or DTD schema.

Yes, standard CDATA sections and comments are preserved through formatting and minification.

Yes, namespace prefixes and declarations are treated as normal attributes and elements and are preserved as-is.

The validator reports a well-formedness error indicating the document could not be parsed, generally near the problematic tag.

How it works
  1. 1

    Paste your XML

    Add the XML document or fragment into the input area.

  2. 2

    Choose Format or Minify

    Pick whether you want readable indentation or a compact single line.

  3. 3

    Check validation results

    Review any well-formedness errors and their reported location.

  4. 4

    Copy the output

    Copy the formatted or minified XML for your project.

Pro tips
  • ·Well-formedness checks catch unclosed or mismatched tags, but this does not validate against an XSD or DTD schema.
  • ·CDATA sections and comments are preserved through formatting, so it is safe to run on documents that rely on them.
  • ·If an error is reported, check near the location given first, the parser usually stops close to the actual problem.