XML Formatter & Beautifier at a glance
- What it does
- Indent unreadable XML, minify it for transport, and see parser errors immediately.
- Where it runs
- Entirely in your browser — no data is uploaded
- Works offline
- Yes, once the page has loaded
- Cost
- Free, with no account and no usage limit
- Category
- Developer & Code
How to use the XML formatter
- Paste the XML into the input panel, including the declaration line if you have one.
- Choose Beautify to indent each level of nesting, or Minify to collapse the document to a single line.
- Check for errors. A malformed document reports the parser's complaint instead of output.
- Copy the formatted result back into your editor or ticket.
Well-formed versus valid
Two different words that get used interchangeably and should not be.
Well-formed means the syntax is legal XML: every element is closed, tags nest without overlapping, attribute values are quoted, and there is exactly one root element. This is what a parser checks, and what this tool reports on.
Valid means the document also matches a schema - an XSD or DTD that says which elements may appear, in what order, with which attributes. A document can be perfectly well-formed and still be rejected by the service you are sending it to because a required element is missing.
Why XML fails to parse
| Problem | Fix |
|---|---|
A bare & in text or an attribute | Escape it as &. Query strings inside URLs are the usual culprit. |
A < in element content | Escape as <, or wrap the block in <![CDATA[ ... ]]>. |
| Two root elements | Wrap them in a single container element. XML permits exactly one root. |
| Unclosed or self-closing HTML tags | <br> and <img> are legal HTML but not XML. Write <br/>. |
| Mismatched case | XML is case sensitive: <Item> does not close <item>. |
A byte-order mark or blank line before <?xml | The declaration must be the very first thing in the document, with nothing before it. |
Where you still meet XML
JSON took over public web APIs, but XML remains the working format in several places you cannot avoid: SOAP services in banking, insurance and logistics; RSS and Atom feeds; XML sitemaps for search engines; SVG, which is XML under the surface; Office and OpenDocument files, which are zipped XML; Android layouts and manifests; Maven and Ant build files; and SAML assertions in enterprise single sign-on.
Its enduring advantages are attributes, namespaces, comments that survive a round trip, and schema validation as a first-class idea - all things JSON deliberately left out.
Namespaces, and why elements have prefixes
Prefixes such as soap:, xsi: and atom: are namespace declarations, and they exist because XML documents routinely combine vocabularies from different specifications. Without them, two standards that both define an <address> element could not coexist in one document.
The prefix itself is arbitrary and local to the document — what matters is the URI it is bound to in the xmlns: declaration. Two documents using soap: and s: for the same namespace URI are equivalent, which regularly surprises people writing string-matching code against XML.
The other consequence is that XPath queries must be namespace-aware. A query for //Envelope finds nothing in a SOAP document, because the element is in the SOAP namespace and the query is not.
Debugging a SOAP response
SOAP envelopes are where most people still meet raw XML, and they arrive as a single unreadable line. Formatting them makes the structure obvious: an Envelope containing an optional Header and a mandatory Body, with either your response or a Fault inside it.
When a call fails, the useful information is in the Fault: faultcode distinguishes a client error from a server one, faultstring carries the human-readable message, and detail often holds the field-level validation errors that actually tell you what to fix. Those are frequently buried several levels deep and are effectively invisible until the document is indented.
Note that a SOAP fault is usually returned with an HTTP 500 status, so a client that checks only the status code reports "server error" when the real problem is a missing field in your request.
Frequently asked questions
Almost never, but be careful with elements where whitespace is significant - for example the contents of a <pre>-like element or a document using xml:space="preserve". Indentation adds text nodes between elements, which a strict consumer may notice.
Yes. SVG is well-formed XML, so it beautifies and minifies normally. If your goal is a smaller file rather than a readable one, the SVG optimizer strips editor metadata as well.
No. This checks that the document is well-formed. Schema validation needs the schema itself and a validating parser, which browsers do not expose.
No. It is parsed by DOMParser in your own browser. SOAP envelopes containing credentials stay on your machine.
Nothing you enter here leaves your browser
XML Formatter & Beautifier does its work in JavaScript running on your own device. The page loads once, and after that there is no upload step and no server involved — which matters here because API responses, tokens and configuration files are exactly the kind of thing that should not be posted to someone else’s server for formatting.
You can verify this rather than taking our word for it: load the page, disconnect from the internet, and the tool keeps working. Our privacy policy sets out what is and is not collected, and this guide explains why the distinction matters.