XML Formatter
Beautify, validate, and minify XML with proper indentation. Instant syntax highlighting and error detection.
Input XML
Output XML
Actions
Supported File Types
.xml · .html · .xhtml · .svg · .xsd · .xsl · .wsdl · .rss · .atom
Beautify, validate, and minify XML with proper indentation. Instant syntax highlighting and error detection.
.xml · .html · .xhtml · .svg · .xsd · .xsl · .wsdl · .rss · .atom
XML (eXtensible Markup Language) is a text-based markup language designed to store and transport structured data in a way that is both human-readable and machine-parseable. Data is organized into nested elements delimited by opening and closing tags, such as <book><title>XML Developer's Guide</title></book>, optionally decorated with attributes.
XML underpins a huge range of technologies still in daily use: SOAP APIs, RSS/Atom feeds, configuration files (Maven pom.xml, Android layouts, .NET config), SVG graphics, WSDL service definitions, XSD schemas, and countless enterprise data exchange formats. Unlike JSON, XML supports comments, namespaces, attributes, mixed content, and processing instructions, which makes it more verbose but also more expressive for document-centric data.
An XML Formatter takes raw, minified, or inconsistently indented XML and reorganizes it into a clean, properly nested, human-readable structure — commonly called "pretty-printing" or "beautifying." Along the way it parses the document to confirm it is well-formed, surfacing any syntax problems instead of silently producing garbled output.
This XML Formatter runs entirely in your browser using the native DOMParser and XMLSerializer APIs, so no markup ever leaves your device. It lets you format XML with 2, 4, or 8-space indentation, minify XML down to a single compact line, validate XML on demand with line/column error hints, upload files directly (.xml, .html, .xhtml, .svg, .xsd, .xsl, .wsdl, .rss, .atom), and copy or download the result — all backed by a Monaco code editor with XML syntax highlighting.
Paste XML into the input editor, type it directly, or upload a file (.xml, .html, .svg, .xhtml, .xsd, .xsl, .wsdl, .rss, .atom) using the upload panel below the editor. Click "Sample" to load a ready-made example instead.
Pick 2, 4, or 8 spaces from the "Indentation" dropdown in the Actions panel on the right. This applies whenever you click Format or Validate.
Click "Format / Beautify XML" to reindent it, "Minify XML" to collapse it to a single compact line, or "Validate XML" to check it is well-formed and see the beautified result at the same time.
The output editor shows the processed XML along with a Valid/Invalid badge. If the document isn't well-formed, the output panel instead shows a detailed error explaining the likely cause.
Use "Copy Output" to copy the result to your clipboard, or "Download XML" to save it as a .xml file.
Every opening tag needs a matching closing tag, e.g. <price>44.95</price>. A tag like <price>44.95 with no closing </price> makes the whole document invalid.
The closing tag must exactly match the opening tag, including case — <Book>...</book> is invalid because XML is case-sensitive. It must be <Book>...</Book>.
Elements must close in the reverse order they were opened. <a><b></a></b> is invalid; it must be <a><b></b></a>.
A well-formed XML document must have exactly one top-level (root) element that contains everything else. Two sibling elements at the top level, e.g. <a/><b/> with no common parent, will fail to parse.
The characters &, <, and > have special meaning and must be escaped as &, <, and > when they appear in text content or attribute values — otherwise the parser treats them as markup and fails.
Attribute values must be wrapped in matching single or double quotes, e.g. id="bk101". A value like id=bk101 or a mismatched quote such as id="bk101' is invalid.
Raw &, <, or > inside element text (outside a <![CDATA[ ... ]]> section) will break parsing. Wrap content containing these characters in a CDATA section instead of escaping it if it's large or code-like.
A compact, single-line XML fragment beautified with 2-space indentation.
Input
<book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book>
Output
<book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <price>44.95</price> </book>
The same document collapsed back down to a single line to reduce payload size.
Input
<book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <price>44.95</price> </book>
Output
<book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book>
Validating a document with a closing tag that doesn't match its opening tag surfaces a clear, actionable error.
Input
<catalog>
<book id="bk101">
<title>XML Developer's Guide</title>
</Book>
</catalog>Output
XML Validation Error Invalid XML. Mismatched opening and closing tags. Common causes: - Unclosed tags (e.g. <tag> without </tag>) - Mismatched tag names - Unquoted or missing attribute values - Invalid characters (&, <, > outside CDATA)
No. This tool runs entirely client-side in your browser using the native DOMParser and XMLSerializer APIs. Your XML never leaves your device or gets sent to a server.
Formatting (beautifying) adds indentation and line breaks so the element hierarchy is easy to read. Minifying strips whitespace between tags to produce the smallest possible payload, which is useful for reducing SOAP request/response size or feed file size.
Most failures come from the document not being well-formed: an unclosed tag, mismatched opening/closing tag names, improperly nested elements, more than one root element, or an unescaped &, <, or > in text content. The error message includes a line and column number when the parser can determine one.
No, it only checks that the document is well-formed XML (correct syntax and nesting). It does not validate against an XSD schema or DTD, so a document can pass here while still being invalid against a specific schema.
These characters are part of XML's own syntax — < and > delimit tags, and & starts an entity reference. If they appear literally in text or attribute values, the parser can't tell them apart from markup, so they must be written as &, <, and >, or placed inside a CDATA section.
You can upload .xml, .html, .xhtml, .svg, .xsd, .xsl, .wsdl, .rss, and .atom files. The contents load directly into the input editor for formatting, minifying, or validation.
Since everything runs in your browser, the practical limit depends on your device's available memory rather than a fixed cap. Very large documents (tens of megabytes) may slow down the editor and parsing.