By · Updated

XML Formatter Online

Pretty Print XML, or Minify It to One Line, With Tag Checks

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the XML Formatter works

This XML formatter online tool beautifies, indents and minifies XML. Paste an XML document that came out of an API, a config file or a SOAP response as one long line and read it back properly indented, one element per line, with nesting you can follow. Switch to Minify to strip the whitespace and comments back out when the document has to travel. Mismatched or unclosed tags are reported rather than silently formatted.

XML formatter online: whitespace and attributes

XML does not care about whitespace between elements, and neither do the libraries that generate it, which is why so much of it arrives as a single unbroken line. That is fine for a parser and useless for a person. Formatting puts each element on its own line and indents children under their parent, so the structure of the document — which elements contain which — becomes visible without reading every angle bracket.

Mixed content is kept inline. An element whose only child is text, like <name>Ada</name>, is written on one line rather than being split across three, because breaking it would make simple records three times longer without making them clearer. Elements that contain other elements are expanded, and empty elements are collapsed to the self-closing <tag/> form. An element whose text is mixed with child elements, or spans several lines, is copied exactly as written in both modes, since its spaces and line breaks are part of its content.

Comments, processing instructions and CDATA survive formatting. Each gets its own line at the correct indent, and the contents are never touched — a CDATA block can hold angle brackets and ampersands that would otherwise need escaping, and that is exactly why it exists. Minify drops comments, on the assumption that a minified document is going to a machine, except inside mixed content, which is copied as written. It keeps everything else including the XML declaration and any DOCTYPE.

Validation here means well-formedness, not schema validation. Before anything is reformatted the tool walks the tag structure and checks that every opening tag has a matching closing tag in the right order, that there is exactly one root element, and that no text appears outside it. If that fails you get a message naming the tag it expected and the tag it found, which is usually enough to locate the problem. It does not check the document against an XSD or DTD, does not resolve namespaces, and does not know whether a <price> element should contain a number.

Attributes are normalised lightly. Whitespace around the = in an attribute is removed, and multiple spaces between attributes collapse to one, but quote style is preserved: an attribute written with single quotes stays single-quoted. The order of attributes is never changed, since some tools that consume XML — despite the specification saying they should not — care about it.

Indentation is a choice of convention. Two spaces is the common default for hand-edited configuration, four spaces mirrors most XML produced by IDEs, and tabs let each reader set their own width. None of them changes what the document means. If you need the document as a single line again, Minify produces one with no whitespace between elements, which is the smallest form that still parses identically.

FAQ

Does this send my XML anywhere?

No. The formatting runs entirely in your browser and the text is never uploaded. That matters for XML in particular, because configuration files and API responses routinely contain credentials, internal hostnames and customer data that should not be pasted into a third-party service.

Why does it say a tag is mismatched when the file opens fine elsewhere?

Browsers and some parsers are forgiving with HTML-style markup, but XML is strict: every tag must be closed, and nesting must be exact. The message names the closing tag it expected and the one it actually found, so look at that point in the source for a missing or misspelled closing tag.

Will formatting change the meaning of my document?

Only whitespace between elements is added or removed. Text inside elements, attribute values, CDATA sections and processing instructions are copied through exactly. Whitespace-sensitive documents where inter-element spacing matters — rare, but possible — should be checked after formatting.

What happens to comments when I minify?

They are removed. Minify is intended for documents going over the wire or into storage, where comments only add bytes. If you need comments kept in a compact document, use Format with two-space indentation instead, which is close to minimal while still readable.

Can it convert XML to JSON?

Not this tool — it only reformats. Once the XML is well-formed and readable, the XML to JSON converter in the related tools will turn it into a JSON structure you can use in code.

See also: all Data & Encoding tools, Dev Utilities, Formatters & Validators, Security & Identifiers, SEO, Accessibility, AI.

Related tools