XML Formatter
Format, validate, and minify XML with clear parse errors. Indentation control and full privacy — everything runs in your browser.
Beautify or minify XML with real parse validation — the browser’s XML parser is the authority, so malformed tags, unclosed elements, and bad nesting report the exact line and reason instead of producing mangled output.
How to use XML Formatter
- Paste the XML.
- Choose an indent, then Beautify or Minify.
- Fix what the validator reports, or copy the clean result.
Who it is for
Developers debugging SOAP payloads and RSS feeds, integrators reading vendor XML, and students learning why XML is stricter than HTML.
How it works
- Beautify indents element content only: whitespace-only text between tags is dropped, but real text stays inline with its element.
- Attributes are re-escaped correctly, comments survive, and minify re-serialises through XMLSerializer for spec-exact output.
- Parse errors quote the browser parser’s own message — unclosed tags name their position.
What it cannot do
- Namespaces are preserved as written but not resolved against external schemas; there is no XSD validation.
- Very large documents (tens of MB) are better handled by command-line tools.
Sample input & output
<invoice currency="USD"><id>INV-204</id><line qty="2">Hosting & SSL</line></invoice>
<invoice currency="USD"> <id>INV-204</id> <line qty="2">Hosting & SSL</line> </invoice> (validated via DOMParser with inline text preserved and entities kept well-formed).
Frequently asked questions
Why did my file fail when the vendor says it is valid?
The vendor may accept fragments or loose syntax the XML spec forbids. The error message names the exact spot — compare it against the spec.
Does it keep comments?
Yes, in both directions; minify keeps them too since they are data, not whitespace.
Can it validate against an XSD schema?
No — it validates well-formedness (the grammar of XML), not schema conformance.
What is the difference between well-formed XML and schema-valid XML?
Under the W3C Extensible Markup Language (XML 1.0) specification, a document is well-formed if it has exactly one root element, properly nested start and end tags with case-sensitive matching, quoted attribute values, and escaped special characters (< and &). Schema validity goes further by checking element names, cardinalities, and data types against an external DTD, XSD, or RelaxNG grammar — this formatter checks well-formedness only.
Why does adding indentation inside mixed-content XML elements break downstream parsers?
In XML, every whitespace character inside an element that carries text is significant character data unless xml:space or a schema declares element-only content. Turning <p>Hello <b>world</b>!</p> into multi-line indented lines injects newline and space text nodes around <b>, causing word spacing glitches in XSLT, DOCX WordprocessingML, and SVG <tspan> runs. Safe beautification indents purely structural parent tags while keeping text-bearing elements inline.
How are CDATA sections, XML comments, and predefined entities handled during formatting?
XML reserves five predefined character entities: &, <, >, ", and '. Unescaped ampersands in URLs (such as ?a=1&b=2) are the single most common reason an XML feed fails DOMParser validation; they must be written as &b=2. During serialization through the browser's XMLSerializer, comments are retained in beautify mode and attribute quotes and character entities are emitted in canonical spec-compliant form.
Does the browser XML parser expand external entities (XXE) when checking untrusted XML?
No. Modern web browsers implement DOMParser for application/xml without fetching external DTD subsets or resolving SYSTEM external general entities (<!ENTITY xxe SYSTEM "...">). Because parsing occurs inside your browser's sandboxed DOM engine with external entity expansion disabled by design, inspecting third-party SOAP payloads, RSS feeds, SAML assertions, or configuration files locally cannot trigger Server-Side Request Forgery or local file disclosure.