XF
XML Formatter, Minifier & Validator
Pretty-print, minify or validate XML using your browser's built-in XML engine — fast and completely offline.
More Developer Tools Tools
How to Use XML Formatter, Minifier & Validator
Paste XML into the box, then choose Format to indent it with one element per line, Minify to strip all whitespace between tags down to a single compact line, or Validate to check it is well-formed. All three use the browser's native DOMParser/XMLSerializer, so parsing behaviour matches what browsers themselves accept.
About XML Formatter, Minifier & Validator
XML (Extensible Markup Language) is a markup format built around nested, explicitly-closed tags — <tag>content</tag> — and it still underpins a huge amount of infrastructure: SOAP APIs, RSS/Atom feeds, SVG images, Android layout files, Microsoft Office's .docx/.xlsx internals, countless enterprise data interchange formats, and configuration for tools like Maven and Ant. Unlike JSON, XML supports attributes on elements, mixed content (text and child elements together), namespaces, and a formal notion of "well-formedness" independent of any particular schema.
Because XML is verbose by nature (every element needs both an opening and closing tag), it is very commonly minified for transmission — stripping the whitespace between tags shrinks payload size — and just as commonly pretty-printed for reading, since minified or machine-generated XML (a single line with no indentation) is close to unreadable by eye. This tool does both, along with a validator that reports whether a document is well-formed XML.
Rather than implement a custom XML parser — a genuinely hard problem to get fully correct, given namespaces, CDATA sections, processing instructions, entity references and DTD subtleties — this tool uses the browser's own built-in DOMParser and XMLSerializer. Every modern browser ships a battle-tested XML engine as part of its web platform (the same one used to render SVG and parse XHTML), so formatting and validation here inherit that correctness rather than reinventing it. When DOMParser encounters malformed XML, it does not throw a JavaScript exception — instead it returns a document containing a <parsererror> element in place of the content, and this tool detects that element and surfaces its message as a validation error.
One practical implication of using DOMParser is that this tool validates well-formedness (are the tags balanced, are attributes quoted, is there exactly one root element, are special characters like & and < properly escaped) rather than schema validity (does the document conform to a specific XSD or DTD). Well-formedness is a property of XML syntax itself and applies to every XML document regardless of what it represents; schema validity is specific to one particular document type and would require the actual schema file, which is out of scope for a general-purpose formatter. If you need to check a document against a specific XSD, you will need a schema-aware validator, but for catching the vast majority of real-world XML mistakes — an unclosed tag, an unescaped ampersand, mismatched tag names, multiple root elements — well-formedness checking is exactly what is needed.
Because parsing happens through the browser's DOM, whitespace-only text nodes between element tags (the newlines and indentation of a pretty-printed source) are collapsed during minification, and reinserted at two spaces per nesting level during formatting. Content inside CDATA sections and text content within elements is preserved as-is and is not reformatted, since altering it could change the meaning of the document.
Details & Tips
How Format works: the input is parsed with DOMParser into a DOM tree, then walked recursively, inserting a newline and two spaces of indentation per nesting level before each child element's opening tag. Text-only elements (an element whose only child is a text node, e.g. <name>Alice</name>) are kept on one line rather than being split across three lines, which keeps the output readable rather than needlessly sparse.
How Minify works: the same DOM tree is serialized back out with XMLSerializer, and whitespace-only text nodes between tags (the indentation and line breaks of a pretty document) are removed before serialization, collapsing the whole document onto a single line. Meaningful whitespace inside text content (e.g. <p> hello world </p>) is left untouched, since removing it would change the document's actual data.
How Validate works: DOMParser is asked to parse the input as "application/xml". If the input is not well-formed, the resulting document contains a <parsererror> element (this is standard, specified browser behaviour, not a custom error format) instead of your intended content; this tool checks for that element and, if found, reports it as an error along with whatever diagnostic text the browser embedded in it (browsers vary in how much detail they include, but Chromium and Firefox both typically include a line/column reference).
Limitations: this tool checks well-formedness, not validity against a specific DTD or XSD schema — a document can be perfectly well-formed XML while still violating a schema's rules about which elements or attributes are allowed. XML declarations (<?xml version="1.0"?>), comments, and processing instructions are preserved through formatting and minification. Namespace prefixes are preserved as written; the tool does not attempt to normalize or resolve namespace URIs. Extremely large documents (multiple megabytes) may be slow to format in-browser since the entire DOM tree is built and walked in memory.
Worked example — minifying:
Input: a multi-line, indented <catalog><book id="1"><title>XML Basics</title></book></catalog>
Minified output: <catalog><book id="1"><title>XML Basics</title></book></catalog> as one unbroken line with no whitespace between tags.
Frequently Asked Questions
Does this tool validate against an XSD or DTD schema?
No. It checks that the XML is well-formed (properly nested tags, balanced quotes, one root element, valid character escaping) using the browser's built-in parser, not that it conforms to a specific schema.
What library does the XML formatter use?
None — it uses DOMParser and XMLSerializer, which are built into every modern browser as part of the web platform, the same engines browsers use internally to render SVG and XHTML.
Will formatting change my data?
No. Formatting only adds or removes whitespace between tags for readability; actual element, attribute and text content is preserved exactly, including inside CDATA sections.
How do I know if my XML has an error?
Click Validate. If the document is not well-formed, the browser's parser reports a parsererror, and this tool surfaces that message, often including a line and column reference to the problem.
Does minify remove whitespace inside text content, like inside a <p> tag?
No, only whitespace-only text nodes between tags (from indentation) are removed. Whitespace that is part of actual text content is left alone since removing it could change the document's meaning.
Can this tool handle XML namespaces?
Yes, namespace-prefixed elements and attributes are parsed and preserved correctly, since DOMParser is namespace-aware. The tool does not modify or resolve namespace URIs.
Is there a file size limit?
There is no hard-coded limit, but very large documents (several megabytes) may be slow to process since the whole document is parsed into memory in your browser tab.
Does it support XML comments and processing instructions?
Yes, comments (<!-- -->) and processing instructions (<?...?>) are preserved through both formatting and minification.
Is my XML uploaded anywhere?
No, all parsing, formatting, minifying and validating happens locally in your browser. Nothing is sent to a server.
Why does my XML fail validation even though it looks fine?
Common causes are an unescaped ampersand (& should be &), a tag that is opened but never closed, mismatched opening/closing tag names, or more than one root element — XML requires exactly one top-level element.
Part of These Collections
Also Available As
xml formatter, xml minifier, xml validator, pretty print xml, format xml online, xml beautifier, well-formed xml checker
Explore More Tools
View all toolsFound a Problem?
Let us know if something with XML Formatter, Minifier & Validator isn't working as expected.
Something went wrong. Please try again.
Thanks — we'll take a look.