XML Formatter & Validator Online
Pretty-print, minify or validate XML instantly. Choose 2 spaces, 4 spaces or tabs, see clear well-formedness errors, and preserve parsed text whitespace in mixed content and xml:space subtrees. Free, private and browser-based.
Your text never leaves your browser.
Formatted XML
Paste XML or open a local .xml, .rss, .svg or .txt file to validate and format it.
XML formatting options
Checks XML 1.0 well-formedness only. XSD schemas and DTD rules are not validated. Mixed content and xml:space="preserve" keep their text whitespace after XML parsing.
How to format XML online
Paste XML into the input, open a local .xml, .rss, .svg or .txt file, or load the sample. The tool checks well-formedness as you type. Keep Pretty Print selected for readable output with 2 spaces, 4 spaces or tabs, switch to Minify for compact output, or choose Validate Only to check a document without changing it. Copy the result, download it as an .xml file, or send it back to the input with Use as input.
What XML formatting does
Formatting rewrites the whitespace between elements so the document's structure is visible: each child element starts on its own line and is indented one level deeper than its parent. Element names, attributes, namespaces, text, comments, CDATA sections and processing instructions are kept. An XML declaration is kept when present and never added when missing.
<root><a>one</a><b>two</b></root>
<root> <a>one</a> <b>two</b> </root>
Pretty Print vs Minify
Pretty Print is for reading, reviewing and diffing. Minify removes formatting whitespace between elements to make documents smaller for storage or transport. Both only reformat structural content, where an element holds child elements, comments or processing instructions and nothing but whitespace text. Most XML consumers ignore that whitespace, but some treat every whitespace node as data, so check your consumer before relying on minified output.
<root> <a>one</a> <b>two</b> </root>
<root><a>one</a><b>two</b></root>
XML well-formedness vs XSD schema validation
A well-formed document follows XML's syntax rules: one root element, properly nested and matching tags, quoted attribute values, no duplicate attributes and only defined entities. Schema validation is a separate, stricter check: an XSD, RELAX NG schema or DTD says which elements and attributes are allowed and what their values must look like. This tool checks well-formedness only. A well-formed document can still be invalid for the vocabulary your application expects.
Common XML syntax errors
Errors are reported by your browser's built-in XML parser. Wording and column numbers differ between browsers, so a position is shown only when the parser provides one. Malformed XML is never repaired automatically. XML 1.0 is supported; declarations for other XML versions are rejected because browser support is inconsistent.
| Problem | Malformed | Well-formed |
|---|---|---|
| Mismatched tags | <root><item></root> | <root><item/></root> |
| Two root elements | <a/><b/> | <list><a/><b/></list> |
| Unquoted attribute | <p id=1/> | <p id="1"/> |
| Unescaped ampersand | <t>A & B</t> | <t>A & B</t> |
| Undefined entity | <t> </t> | <t> </t> |
| Case mismatch | <Item></item> | <Item></Item> |
XML only predefines &, <, >, " and '. HTML names such as need a numeric reference instead; the HTML Entity Encoder & Decoder can convert them.
Why whitespace and mixed content matter
In XML, whitespace inside text is data. An element with mixed content, meaning text alongside child elements, cannot be re-indented without changing that text: splitting <p>Hello <b>world</b> !</p> over several lines would add spaces and line breaks to the paragraph. This tool leaves mixed-content elements, text-only elements, CDATA and anything inside xml:space="preserve" without adding or removing text whitespace after parsing. XML parsing normalizes literal CRLF and CR line endings to LF, and normalizes literal attribute whitespace. Only Validate Only returns the original input unchanged.
<doc><p>Hello <b>world</b> !</p></doc>
<doc> <p>Hello <b>world</b> !</p> </doc>
Working with XML files, RSS feeds, sitemaps and SVG source
RSS and Atom feeds, sitemap.xml files, SVG graphics, Office and Android resource files, SOAP messages and many configuration formats are XML. Open a UTF-8 file up to 1 MiB, or paste up to 1,000,000 characters (UTF-16 code units). Larger input is never truncated. Serialization can normalize details that do not change meaning: attributes use double quotes, empty elements become self-closing and character references may be written as characters. Files must contain UTF-8 text; a retained encoding declaration describes the source and is not used to decode files. Downloads use UTF-8 and update an existing encoding declaration to UTF-8 so the bytes and declaration agree. To review exactly what changed, compare the input and output with the Text Difference Checker.
XML privacy and safe processing
Everything runs in your browser and nothing is uploaded or stored. XML is treated as untrusted text: parsed nodes are never inserted into the page, SVG is never rendered, scripts and event handlers never run, and URLs are never opened. Documents with a DOCTYPE are rejected, so DTD entities, including external entities and entity-expansion attacks, are never resolved or fetched.
Related CleanGlyph tools
Format and validate JSON with the JSON Formatter & Validator, escape markup with the HTML Entity Encoder & Decoder, strip tags from copied markup with the HTML Tag Remover, or compare two documents with the Text Difference Checker.
Frequently asked questions
How do I format XML online?
Paste XML into the input or open a local .xml, .rss, .svg or .txt file. Keep Pretty Print selected and choose 2 spaces, 4 spaces or tabs. The formatted result appears as you type, and you can copy it, download it as an .xml file or use it as new input.
Does this tool validate XML against an XSD schema?
No. It checks well-formedness: matching and properly nested tags, a single root element, quoted attributes and valid entities. Schema validation against XSD, RELAX NG or DTD rules checks whether the content follows a vocabulary, which requires the schema and is not performed here.
Why was my XML not indented inside some elements?
Elements that contain text mixed with child elements, such as <p>Hello <b>world</b> !</p>, and elements marked xml:space="preserve" keep their text whitespace after XML parsing. Adding or removing indentation there would change the text itself, so the tool leaves those subtrees alone. Parsing can still normalize line endings and entity spellings; Validate Only returns the original input unchanged.
Is minified XML always equivalent to the original?
Minify removes formatting whitespace in structural content containing elements, comments or processing instructions. It never strips text-only, mixed-content or preserved subtrees. Some XML consumers treat every whitespace node as data. If yours does, use Validate Only to keep the input unchanged.
Why is my DOCTYPE rejected?
DTDs can declare entities that expand to huge amounts of text or reference external files and URLs. To keep processing safe, documents with a DOCTYPE declaration are rejected as unsupported and their entities are never resolved or fetched. Remove the DOCTYPE to format the rest of the document.
Why does the error position differ between browsers?
The tool uses your browser’s built-in XML parser, and each browser words its errors and counts columns differently. A line and column are shown only when the parser reports them; the tool never guesses a position.
Will formatting change my text, attributes or CDATA?
Parsed text values, attribute values, comments, processing instructions and CDATA content are preserved. XML parsing normalizes literal CRLF and CR line endings to LF and normalizes literal attribute whitespace. Attributes are written with double quotes, empty elements become self-closing, and character references such as A may be written as the character they represent. This is not a byte-for-byte transformation; Validate Only keeps the input unchanged.
Can I format RSS feeds, sitemaps and SVG files?
Yes. RSS, Atom, sitemap.xml and SVG are XML, so they can be validated and formatted here. SVG source is shown only as plain text and is never rendered, so scripts and links inside it are not executed or followed.
Is my XML uploaded or stored?
No. Parsing and formatting run entirely in your browser. Opened files are read locally, nothing is sent to a server, and your XML is not saved after you close the page.