XML Formatter, Validator & Minifier Online

Paste XML to check well-formedness, pretty-print nested elements, or remove indentation for a compact result. Processing runs locally in your browser and preserves mixed text, CDATA, namespaces, and xml:space="preserve" content.

XML formatter, validator, and minifier tool

Formatting and minification settings
Indentation
Minification
Whitespace policy

Format and Minify replace whitespace-only indentation in element-only content. Existing spacing is retained in mixed-content and xml:space="preserve" subtrees.

1. Input XML

Paste, type, choose, or drop a local XML-family file. Press Ctrl/Cmd + Enter to format.

1 line · 0 characters · 0 BLine 1, column 1
No file selected. Drop a local XML-family file onto the editor.
2. Process

3. Output XML

Output preserves original markup lexemes where possible. Always review whitespace-sensitive documents.

1 line · 0 characters · 0 BNo output yet
Ready Add XML, then validate, format, or minify it.

Advertisement

How to format, validate, or minify XML

  1. Add XMLPaste XML, load the sample, or choose or drop a local XML-family file.
  2. Choose settingsSelect 2 spaces, 4 spaces, or tabs. Decide whether minification may remove comments.
  3. Process itValidate for well-formedness, format for reading, or minify to remove indentation.
  4. Review and exportCheck the result and whitespace assumptions, then copy or download the XML.

XML formatting example

Element-only content is indented, while inline mixed content such as text around <em> remains unchanged.

Compact input

<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><author>Ada</author></book><note>Read <em>carefully</em> today.</note></catalog>

Formatted output

<?xml version="1.0"?>
<catalog>
  <book id="b1">
    <title>XML Basics</title>
    <author>Ada</author>
  </book>
  <note>Read <em>carefully</em> today.</note>
</catalog>

XML formatting and validation guide

Well-formed XML versus schema-valid XML

This tool checks well-formedness: one root element, correct nesting and case, quoted attributes, valid namespace bindings, and legal XML syntax. Schema validation is a separate step that checks an already well-formed document against XSD, Relax NG, or application rules.

Formatting strategy

The formatter first requires valid XML, then works from the original lexical text. It inserts indentation only around element-only content. It does not use XMLSerializer, so it avoids unnecessarily rewriting prefixes, attribute spellings, CDATA sections, declarations, and DOCTYPE text.

Mixed content and xml:space

XML can mix words and child elements, as in <p>Read <em>this</em> now.</p>. Adding line breaks there changes text. The formatter therefore preserves the original subtree when an element has direct non-whitespace text or inherits xml:space="preserve".

What minification means for XML

Unlike HTML, XML has no general rule that indentation is insignificant. This minifier removes whitespace-only nodes only in content that appears element-only, and optionally removes comments. That is useful for many feeds, configuration files, and data documents, but it is not a semantic guarantee.

Namespaces, CDATA, and entities

Namespace prefixes are retained as written. CDATA is treated as text and preserved verbatim. Entity references remain lexically unchanged in output; the browser parser must still be able to resolve every entity for validation to succeed.

Useful keyboard workflow

Use Ctrl/Cmd + Enter to format and Ctrl/Cmd + Shift + M to minify. The editor reports UTF-8 bytes, lines, characters, and the cursor location.

Important XML limits and assumptions

  • No XSD or DTD grammar validation: the result only confirms browser-parsed XML well-formedness.
  • No external resource resolution guarantee: browser parsers are not a replacement for a controlled catalog-aware XML processor.
  • Whitespace may be data: formatting and minification can replace or remove whitespace-only text nodes outside recognized mixed-content or xml:space="preserve" regions.
  • Comments may matter: comment removal is opt-in and cannot be reversed.
  • Interactive size limit: input above 5 MiB is refused; input above 1 MiB receives a performance warning.
  • Browser diagnostics vary: line and column details are shown when the browser exposes them; otherwise the first structural problem found by the tool is reported.

Explanatory content last reviewed: .

XML formatter, validator, and minifier FAQ

What makes an XML document well-formed?

A well-formed document has one root element, properly nested and case-matched tags, quoted attribute values, legal names and characters, and correctly formed declarations, comments, CDATA sections, and entity references.

Does this tool validate against an XSD or DTD?

No. It checks XML well-formedness with the browser's XML parser. It does not validate document structure or data types against an XSD, Relax NG schema, or DTD grammar.

Will formatting change XML data?

The formatter preserves existing text in mixed-content and xml:space="preserve" elements, but it replaces whitespace-only indentation in element-only content. Because an application can treat any whitespace node as data, review the result before production use.

What does XML minification remove?

It removes whitespace-only text between markup where the element has no direct text content and is not under xml:space="preserve". Comments are removed only when selected. It does not rename elements, rewrite attributes, or alter CDATA text.

Are namespaces, CDATA, and processing instructions supported?

Yes. Native parsing validates namespace usage, while the output process retains namespace prefixes, CDATA sections, processing instructions, XML declarations, and document type declarations as written.

Can this tool resolve external entities?

Do not rely on browser XML parsers to fetch or resolve external DTDs or entities. For documents that depend on an external catalog or schema, use a controlled XML toolchain with explicit resource-resolution rules.

Is minified XML reversible?

No. Formatting can add indentation, but it cannot recover removed comments or the author's original whitespace. Keep the original XML in version control or another safe location.

Is my XML uploaded or stored?

No. This tool processes editor contents in the current browser tab, does not upload them, and does not save them to local storage. Choosing a file reads it locally.

How large can an XML file be?

The tool accepts up to 5 MiB for an interactive browser session and warns above 1 MiB. Browser memory and speed vary, so a streaming desktop or command-line parser is better for very large documents.

Explore more tools