XML Formatter Online — Beautify, Indent & Validate XML Free
An XML formatter online takes minified or unindented XML and reformats it with proper indentation and line breaks, making the structure of nested elements immediately visible. It also validates the XML for well-formedness — catching unclosed tags, mismatched brackets, and illegal characters before they cause parsing errors in your application.
What Is XML?
XML (eXtensible Markup Language) is a text format for representing structured data using nested tags. Unlike HTML, XML does not have predefined tags — you define your own tag names to describe your data. It is used for configuration files (Maven POM files, Spring beans, Android resources), data exchange (SOAP web services, RSS and Atom feeds), document formats (DOCX, SVG, OpenDocument), and many other purposes.
While JSON has largely replaced XML for new REST API designs, XML remains heavily used in enterprise systems, legacy integrations, and formats where document-centric structure and attributes are important.
How to Use the XML Formatter
- Paste your XML. Paste minified, single-line, or poorly indented XML into the input area.
- Format. Click Format. The tool parses the XML, validates its structure, and outputs a properly indented version.
- Review any errors. If the XML is not well-formed (for example, an unclosed tag or an invalid character), the formatter shows an error message identifying the problem.
- Copy the result. Copy the formatted XML to use in your editor, documentation, or code.
XML Well-Formedness Rules
An XML document is well-formed if it follows these rules. The formatter validates all of them:
| Rule | Example of Violation |
|---|---|
| Single root element | <a/><b/> — two root elements |
| All tags must be closed | <item>value — no closing tag |
| Tags must be properly nested | <a><b></a></b> — crossed closing tags |
| Attribute values must be quoted | <item id=123> — unquoted attribute |
| Special characters must be escaped | <name>A & B</name> — ampersand must be & |
| Tag names are case-sensitive | <Item></item> — case mismatch |
XML Formatting Options
Indentation size
The standard indentation for XML is 2 or 4 spaces. 2-space indentation is more compact for deeply nested documents. XML configuration files in Java projects (Maven, Spring) conventionally use 4 spaces. The formatter lets you choose your preferred indentation width.
Collapsing empty elements
An element with no children can be written as <item></item> or as the self-closing form <item/>. Both are equivalent. Some formatters convert between these forms; for human readability the self-closing form is typically preferred for genuinely empty elements.
Converting Between XML and Other Formats
XML is often transformed into or from other formats:
- Use the XML to JSON converter to convert XML into JSON format — useful when working with modern APIs that expect JSON.
- Use the JSON to XML converter for the reverse transformation — converting JSON data into XML structure.
- Use the JSON formatter for formatting JSON documents with the same indentation and validation workflow.
Common Questions
What is the difference between well-formed and valid XML?
A well-formed XML document follows the basic structural rules described above — properly nested tags, closed elements, quoted attributes. A valid XML document is both well-formed AND conforms to a specific schema (DTD, XSD, or Relax NG) that defines what elements and attributes are allowed. The formatter checks well-formedness only. Schema validation requires the schema file as an additional input and is typically done in a full XML editor or IDE.
Can I format SVG files?
Yes. SVG is XML-based and can be formatted with any XML formatter. Formatting an SVG file makes it easier to read and edit the element structure manually.
Why does my XML contain entities like & and <?
XML reserves five characters that must be escaped when used in text content or attribute values: & (ampersand), < (less-than), > (greater-than), ' (apostrophe in attribute values), and " (double-quote in attribute values). When an XML document is generated by code, these are automatically escaped to their entity references. The formatter preserves these escapes correctly.
Format Your XML Now
Paste any XML document and get a properly indented, validated, readable result instantly — free, no signup, runs in your browser.
Open XML Formatter