Output appears here.
The XML Formatter pretty-prints XML with consistent indentation, checks that it is well-formed and shows the line and column of the first error. Minify mode strips the formatting back out. Use it for SOAP messages, RSS feeds, sitemaps, Maven pom.xml files and SVG markup. It runs in your browser, and nothing you paste is uploaded.
How to format XML
- Paste XML, drop an
.xml,.svg,.xsdor.rssfile, or press ⌘/Ctrl O. - Choose an Indent and decide whether empty elements should collapse to
<tag/>. Keep Preserve whitespace in text on for documents where text spacing matters. - Copy with ⌥/Alt C or download with ⌘/Ctrl S. Next actions switch to Minify or convert the XML to JSON.
Examples
Book catalog on one line
A catalog as it arrives from an API, with the XML declaration kept and the empty <tags></tags> element collapsed.
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price currency="USD">44.95</price></book><book id="bk102"><author>Ralls, Kim</author><title>Midnight Rain</title><price currency="USD">5.95</price><tags></tags></book></catalog>Result:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price currency="USD">44.95</price>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price currency="USD">5.95</price>
<tags/>
</book>
</catalog>SOAP envelope with namespaces
Namespace prefixes and xmlns declarations are kept exactly as written.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><m:GetPrice xmlns:m="https://example.com/prices"><m:Item>Apples</m:Item></m:GetPrice></soap:Body></soap:Envelope>Result:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:GetPrice xmlns:m="https://example.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>Mismatched closing tags
Two elements closed in the wrong order. The formatter refuses to guess and reports the mismatch.
<a><b>x</a></b>Result:
Expected closing tag 'b' (opened in line 1, col 4) instead of closing tag 'a'. (line 1, column 8)
A closing tag does not match the most recently opened tag.Options explained
- Indent — the whitespace used for each nesting level: 2 spaces, 4 spaces or a tab.
- Collapse empty tags — writes an element with no content, such as
<tags></tags>, as the shorter self-closing<tags/>; turn it off to keep explicit open and close tags. - Preserve whitespace in text — keeps text nodes and mixed content (text with inline elements, like
<p>Hello <b>world</b></p>) on one line exactly as written; when off, every text node and child element goes on its own line with its surrounding whitespace trimmed.
Common XML errors
XML is stricter than HTML: every element must close, attributes must be quoted and there must be exactly one root. The formatter checks well-formedness before printing, so these are the messages you will meet.
Expected closing tag … instead of closing tag
Elements are closed in a different order than they were opened. XML requires strict nesting: the most recently opened element closes first.
Unclosed tag
An element is opened and never closed, often because the input was truncated or a closing tag was deleted. Add the missing </tag>, or use <tag/> for an empty element.
Attribute is without value
An attribute such as href=x or a bare disabled has no quoted value. Write attributes as name="value".
Multiple possible root nodes found
Two or more top-level elements, such as <a>1</a><b>2</b>. Wrap them in a single parent element.
char '&' is not expected
A raw ampersand or less-than sign inside text. Escape & as & and < as <, or wrap the text in a <![CDATA[ … ]]> section.
"This looks like HTML"
HTML allows void elements such as <br> and <img> without a closing tag, which XML does not, so an HTML page fails to parse. When the input has an HTML doctype or unclosed void elements, the hint says "This looks like HTML" in place of the generic one, whatever the parser error was. Use the HTML Formatter for web pages.
FAQ
Is it safe to format XML that contains credentials?
Yes. SOAP headers often carry usernames, passwords or signed tokens, and none of it leaves your device: the formatter runs in your browser inside an isolated frame that blocks network requests, and nothing is stored on a server. Settings are remembered locally, but the input is only kept if you turn on "Remember my last input".
Does the formatter validate against an XSD or DTD?
No. It checks that the document is well-formed — correctly nested, closed and quoted, with a single root. It does not load schemas or DTDs, so it cannot tell you whether an element is allowed at a given position. A well-formed document is the prerequisite for schema validation elsewhere.
Will pretty-printing change my data?
Element names, attributes, namespaces and text are kept. With Preserve whitespace in text on, text content and mixed content stay exactly as written. Turning it off adds line breaks between text and inline elements, which changes whitespace-sensitive content, so leave it on for documents where spacing inside text is meaningful.
How do I minify XML?
Switch the mode to Minify. It removes the indentation and line breaks between elements, collapses empty elements when Collapse empty tags is on, and shows the size before and after. The XML declaration is kept. Minified XML is what you usually want in a request body or a config value.
Can I format SVG, RSS or a sitemap?
Yes. SVG, RSS, Atom, sitemaps, .plist and WSDL files are all XML, and the formatter accepts those file types directly. Namespaced SVG attributes such as xlink:href are preserved. For an RSS feed you want to process in code, XML to JSON turns the items into an array.
Are comments and CDATA sections kept?
Yes. Comments and processing instructions are kept and placed on their own lines, and a CDATA section stays inside its element exactly as written. An ampersand or angle bracket inside CDATA is not an error. Minify mode keeps comments too, so remove them by hand if the output must be as small as possible.
Related tools
To work with the data in JavaScript, convert the XML to JSON with control over attributes and arrays. Going the other way, JSON to XML builds a well-formed document from an object. For web pages, the HTML Formatter handles void elements and inline scripts.