What Is an XML Formatter?
XML (eXtensible Markup Language) is a text format for structured data, built from nested elements like <book><title>…</title></book>. It powers RSS and Atom feeds, sitemaps, SOAP web services, Microsoft Office files (DOCX and XLSX are zipped XML), SVG graphics, Android layouts, Maven and .NET project files, configuration files, KML and GPX maps, and countless enterprise data exchanges. XML generated by software is often written on a single line with no indentation, which is almost impossible for people to read.
This XML formatter (or XML beautifier) re-indents the document so its structure is clear, and the XML minifier does the opposite, stripping unnecessary whitespace to make files smaller for transmission and storage. Both first check that the XML is well-formed.
How to Format or Minify XML
- Paste your XML or drop a file (.xml, .svg, .rss, .xsd, .kml, .gpx, .config and more).
- Choose Format or Minify, and the indentation style.
- Optional: remove comments, or put each attribute on its own line for elements with many attributes.
- Fix any errors: if the XML isn't well-formed, you'll see the error message with its line and column.
- Copy or download the result.
Well-Formed XML Rules
An XML document is well-formed when it follows XML's syntax rules. Every parser rejects documents that break them:
- There must be exactly one root element containing everything else.
- Every start tag needs a matching end tag (
<a></a>), or must be self-closing (<a/>). - Elements must be properly nested:
<b><i></i></b>, never<b><i></b></i>. - Tag names are case-sensitive:
<Item>and<item>are different. - Attribute values must be quoted, and each attribute can appear only once per element.
- Special characters must be escaped:
&<>"'. Or wrap raw text in<![CDATA[…]]>.
Being well-formed is different from being valid, which means matching a schema (XSD or DTD) that defines which elements are allowed. This tool checks well-formedness, the most common source of errors.
Common XML Errors and Fixes
| Error | Typical cause | Fix |
|---|---|---|
| Opening and ending tag mismatch | A missing or misspelled closing tag | Check nesting near the reported line |
| EntityRef: expecting ';' | A bare & in text or a URL | Write &, or use CDATA |
| Extra content at the end of the document | More than one root element | Wrap everything in one root |
| Attribute without value / not quoted | HTML-style attributes | Use name="value" |
| XML declaration allowed only at the start | Whitespace or a BOM before <?xml | Remove anything before the declaration |
XML Formatting in Other Tools
Many code editors can format XML too. VS Code does it with the XML extension, and IntelliJ-based IDEs have built-in formatting. On the command line, xmllint --format file.xml pretty-prints and validates XML on Linux and macOS. This online formatter is handy when you're away from your usual tools, need a quick check of an API response or SOAP message, or want to tidy an SVG before editing it.
XML vs JSON
JSON has replaced XML for most new web APIs because it's shorter and maps directly to JavaScript objects. XML remains essential where documents need attributes, mixed content, namespaces, schemas, comments or digital signatures, as in Office files, SVG, RSS, SOAP, SAML, sitemaps and many banking and government data standards. When you need to move data between the two, use the XML to JSON and JSON to XML converters.
Formatting Large Files
Very large XML files, such as database exports or multi-megabyte sitemaps, are processed entirely in your browser, so speed depends on your device. If a huge file is slow, format a representative section first to inspect its structure.
Frequently Asked Questions
Can I validate XML against an XSD schema here?
This tool checks well-formedness. Schema validation needs the XSD file and a validating parser, such as xmllint --schema.
Why does my formatted XML look different from the original?
Only whitespace between tags changes. Character entities may be written in a normalised form, but the data itself is identical.
Is my XML uploaded?
No. Parsing and formatting use your browser's built-in XML parser, locally.
Does formatting change my data?
Only whitespace between elements changes. Text content, attributes, CDATA and comments are preserved.
Can I format SVG files?
Yes. SVG is XML, so drop the file in to format or minify it.
How do I convert XML to JSON?
Use the XML to JSON converter, which handles attributes and repeated elements.
What's the difference between well-formed and valid XML?
Well-formed means correct syntax. Valid means it also follows a schema (XSD or DTD).