XML Formatter
Paste your XML to beautify, minify or validate it. Detects unclosed tags and syntax errors. Runs in your browser.
Updated July 11, 2026
100% Private & Secure
This tool runs in your browser.
Your data is never uploaded or stored.
Click Format or Minify to see resultsHow to use
- 1
Paste your XML into the input box.
- 2
Click Format to beautify or Minify to compress.
- 3
Copy the result or download it as a file.
When to use it
Reading a minified API response
SOAP services, RSS feeds, and many enterprise APIs return XML collapsed onto a single line. Formatting re-indents the element tree so you can see nesting, attributes, and repeated siblings at a glance.
Fixing malformed config before deploy
Server configs (Maven pom.xml, Spring beans, AndroidManifest) fail loudly when an element is unclosed or an entity is malformed. Formatting and validating locally catches the error before the deploy pipeline rejects it.
Diffing two XML documents
Consistently indented, minified, or canonicalized XML produces clean, meaningful diffs in version control — element-level changes line up instead of being buried in reformatting noise.
Stripping whitespace to shrink a payload
Minifying removes insignificant whitespace between elements, cutting transfer size for large XML feeds and configs sent over the wire.
How it works
Well-formed vs valid: two different bars
The XML 1.0 (Fifth Edition) specification defines a document as well-formed when it obeys the core syntactic rules: exactly one root element, every start tag has a matching end tag, elements nest properly, attributes are quoted, and reserved characters are escaped. A formatter checks well-formedness — it can flag a missing </item> without knowing anything about your schema.
Valid is a stricter, separate bar: a valid document is well-formed and conforms to a DTD or XML Schema (XSD). Validation requires the schema and a validating parser; formatting alone does not perform it. Most "XML validator" web tools, including this one, check well-formedness, not schema validity.
- Well-formed = follows XML syntax rules (one root, balanced tags, escaped entities)
- Valid = well-formed AND conforms to a DTD or XSD
- A document can be well-formed but invalid — syntactically clean yet wrong against your schema
Tags, attributes, namespaces, and escaping
Every XML element is a start tag, content, and end tag: <book>...</book>. Self-closing tags (<br/>) are shorthand for elements with no content. Attributes live inside the start tag and must be quoted: <book id="42"/>.
Because <, >, &, ", and ' have structural meaning, literal occurrences must be escaped as the predefined entities <, >, &, ", and '. For blocks of text containing many such characters (embedded code, SQL, HTML), wrap the content in a CDATA section — <![CDATA[ ... ]]> — which the parser treats as raw text until the closing ]]>.
XML is case-sensitive: <Book> and <book> are two different element types. Namespaces (a separate W3C recommendation) let elements carry a URI-qualified prefix (xmlns:dc="http://purl.org/dc/elements/1.1/") so vocabularies from different sources can coexist without name collisions.
<!-- Self-closing, attribute, entity, and CDATA together -->
<note lang="en">
<to>Lee & Kim</to>
<body><![CDATA[ if (a < b && b < c) { return "<ok/>"; } ]]></body>
<flag/>
</note> How a browser parses and reformats XML
In the browser, XML is parsed with DOMParser into a DOM tree, then re-serialized for pretty-printing. If the source is not well-formed, the parser returns a <parsererror> document instead of the content tree — that is how this tool reports line and column numbers for a missing tag or unescaped ampersand.
Indentation is applied by walking the DOM and emitting one element per line with a depth-based prefix. Minification does the inverse: it serializes the tree with no insignificant whitespace. Both operations round-trip through the same DOM, so formatting then minifying yields the original structure.
Common mistakes & edge cases
"Unclosed element" or mismatched start/end tag
A raw & in text content throws a parse error
Escape & as &. The same applies to < (<), > (>), " (") inside attributes. For large code blocks, wrap in .
Multiple top-level elements are rejected
XML requires exactly one root element. Wrap siblings in a single parent, or use a document fragment approach if your serializer supports it.
<Book> and <book> are treated as different tags
XML is case-sensitive. Match the casing exactly on both the start and end tags; <Book></book> is not well-formed.