XML Formatter and Validator
Pretty-print, minify, and well-formedness-check XML entirely in your browser. Parsing uses the native DOMParser, so tags, attributes, and text round-trip exactly — and no external entities or DTDs are ever fetched.
Input
Result
What this XML formatter does
This tool takes raw XML and runs it through the browser's built-in DOMParser. If the document is well-formed, it walks the resulting DOM tree and re-serializes it. In pretty-print mode it inserts newlines and your chosen indentation (two spaces, four spaces, or a tab) so the structure is readable. In minify mode it strips the insignificant whitespace between tags to produce the most compact equivalent document. In check only mode it reports well-formedness without rewriting anything. Element names, attributes, attribute values, namespaces, and text content are preserved and re-escaped correctly on output.
Crucially, this is well-formedness checking, not validation. A well-formed document has balanced tags, quoted attribute values, a single root element, and properly escaped special characters. It says nothing about whether the document conforms to a DTD, an XSD schema, or a RELAX NG grammar. If you need schema conformance, reach for a dedicated validator — well-formedness is necessary but not sufficient.
When to use it
Reach for this tool when you receive minified or single-line XML — SOAP envelopes, RSS or Atom feeds, Android layout or manifest files, Maven pom.xml, SAML assertions, or signed XML payloads — and you want to read it. It is also handy when you are about to embed XML in a config file or a log and want the smallest well-formed representation, or when a downstream parser rejected your XML and you need to find the exact line and column of the syntax error.
Input and output
The input is any XML document or fragment with a single root element. Paste it into the box, pick a mode and an indent width, and the result updates as you type. The output is the reformatted (or minified, or merely validated) XML, with a badge summarizing the root element name and node count. Use Copy to put it on your clipboard or Download to save it as a .xml file with the application/xml media type. When the input is not well-formed, the output panel shows the parser's error message and, where the browser provides it, the line and column of the failure instead of guessing at a fix.
Security: no DTD or external-entity processing
The browser DOMParser deliberately does not resolve external entities, fetch external DTD subsets, or follow remote document references. That means this tool is not exposed to classic XXE attacks, billion-laughs-style entity expansion against network resources, or server-side request forgery through entity URLs. The flip side is that documents which genuinely depend on a DTD for entity definitions or default attribute values will not have those resolved here — unresolved entity references surface as a parse error rather than being expanded. Treat this tool as a syntax formatter, and do schema-aware processing in your application stack.
Common mistakes
- Expecting schema validation. Well-formed is not the same as valid. This tool never checks a DTD or XSD; a document can pass here and still be rejected by a schema validator.
- Pasting multiple root elements. XML requires exactly one root. A fragment with two sibling top-level elements is not well-formed — wrap it in a container element first.
- Reformatting whitespace-significant content. Pretty-printing normalizes inter-tag whitespace. If your XML stores meaningful spaces or newlines inside elements, use minify or check-only instead of pretty-print.
- Relying on entity expansion. Custom entities defined in an external or internal DTD are not resolved here and will trigger a parse error.
- Unescaped
&,<, or quotes. A bare ampersand or angle bracket in text or an attribute breaks well-formedness — escape them as&,<, and so on.