An XML formatter takes a wall of unindented or minified XML and turns it into a clean, properly indented, human-readable document. XML still powers an enormous share of the world's data exchange: SOAP web services, RSS and Atom feeds, SVG graphics, Android layout files, Maven pom.xml build files, Microsoft Office .docx/.xlsx internals, sitemaps, SAML assertions, and countless enterprise integrations. When that XML arrives as a single 4,000-character line, reading it is miserable. This XML beautifier parses your input, walks the element tree, and re-emits it with consistent two-space indentation so nested tags line up and structure becomes obvious at a glance. It runs 100% client-side in your browser — your XML is never uploaded, never logged, and the tool works offline once the page has loaded.
How to Format XML
Formatting is three quick steps. (1) Paste your raw or minified XML into the input panel. (2) Click Format / Beautify — the tool first attempts a strict parse with the browser's native DOMParser to confirm the document is well-formed, then pretty-prints it. (3) Copy the indented result. To check validity without reformatting, click Validate; to compress XML back to a single line for transport, click Minify. The pretty-printer inserts a newline and the correct indent before every opening tag, keeps text content on the same line as its element when it is short, and preserves attributes in their original order. If the parser detects a problem — a mismatched closing tag, an unescaped &, or an unclosed element — you get the browser's parse-error message so you can locate the issue.
When to Use an XML Beautifier
- SOAP & web services — read the request and response envelopes captured from a legacy integration.
- RSS / Atom feeds — inspect a podcast or blog feed to debug missing items or bad dates.
- SVG editing — format an exported SVG so you can hand-tweak paths, viewBox, or styles.
- Config & build files — tidy a Maven
pom.xml, Spring applicationContext.xml, or Android layout. - Sitemaps — verify a
sitemap.xml is well-formed before submitting it to search engines. - SAML / SSO debugging — decode and format a SAML assertion to confirm the attributes and audience.
- Office documents — explore the XML parts inside a
.docx or .xlsx after unzipping it.
XML Formatting in Code
To pretty-print XML programmatically the way this tool does in the browser:
// Browser: parse then re-serialise with indentation
function formatXML(xml) {
const doc = new DOMParser().parseFromString(xml, 'application/xml');
if (doc.querySelector('parsererror')) throw new Error('Malformed XML');
const PADDING = ' ';
const xsltDoc = new DOMParser().parseFromString([
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">',
' <xsl:output indent="yes"/>',
' <xsl:template match="node()|@*"><xsl:copy>',
' <xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template>',
'</xsl:stylesheet>'].join('\n'), 'application/xml');
const proc = new XSLTProcessor();
proc.importStylesheet(xsltDoc);
return new XMLSerializer().serializeToString(proc.transformToDocument(doc));
}
# Python (standard library)
import xml.dom.minidom
print(xml.dom.minidom.parseString(raw).toprettyxml(indent=' '))
CLI users can run xmllint --format file.xml for the same effect.
Well-Formed vs. Valid & Common XML Errors
There are two different bars XML can clear. Well-formed means the syntax is correct: every tag is closed, tags nest properly, attribute values are quoted, and special characters (& < >) are escaped as & < >. Valid goes further — the document also conforms to a schema (DTD, XSD, or RELAX NG) that defines which elements and attributes are allowed where. This formatter checks for well-formedness via DOMParser; full schema validation requires the matching XSD and a validating parser. The most frequent errors it catches are an unescaped ampersand (write & not &), a mismatched or missing closing tag, multiple root elements (XML allows exactly one), and a stray byte-order mark or invalid character before the <?xml?> declaration. Need the opposite format? Convert structured data with our JSON to YAML tools or beautify JSON instead.