Beautify or minify XML with 2-space, 4-space, or tab indentation. Validates structure and shows errors — see byte savings percentage after minifying.
XML is easy for systems to read but difficult to review when it arrives as one long line. This formatter checks whether a document is well formed, then beautifies it with consistent indentation or minifies it by removing unnecessary whitespace between tags. Processing happens in your browser.
A well-formed document has one root element, correctly nested tags, quoted attributes, and matching opening and closing tags. Empty elements use />. The formatter preserves comments and processing instructions while changing layout.
<catalog>
<item id="1">Example</item>
</catalog>
Well-formedness is different from schema validation. An XSD, DTD, or application validator is still required to check required fields, allowed values, and business rules.
| Mode | Best for | What changes |
|---|---|---|
| Beautify | Reviews, debugging, version control | Adds line breaks and selectable indentation |
| Minify | Network transfer, caches, compact storage | Removes inter-tag whitespace and condenses whitespace |
Beautify mode supports two spaces, four spaces, and tabs. Minify mode keeps the XML structure and removes presentation whitespace; review the result before using it where text-node whitespace is significant.
| Error | Example | Fix |
|---|---|---|
| Mismatched tags | <item></catalog> | Close elements in reverse nesting order |
| Unclosed element | <catalog><item> | Add closing tags or use a self-closing element |
| Unquoted attribute | <item id=1 /> | Use <item id="1" /> |
| Multiple roots | <a /><b /> | Wrap content in one root element |
| Unescaped text | <name>A & B</name> | Encode ampersands as & |
Comments, XML declarations, CDATA sections, and processing instructions are part of XML syntax and should not be removed casually. A declaration commonly appears at the start:
<?xml version="1.0" encoding="UTF-8"?>
<message><!-- kept for reviewers --><![CDATA[raw <text>]]></message>
Formatting improves readability but does not sanitize XML. Treat untrusted XML as data and use a parser with external entity processing disabled on the server.
const parser = new DOMParser();
const document = parser.parseFromString(xmlText, "application/xml");
const error = document.querySelector("parsererror");
if (error) {
console.error("Invalid XML");
}
import xml.etree.ElementTree as ET
root = ET.fromstring(xml_text)
ET.indent(root, space=" ")
formatted = ET.tostring(root, encoding="unicode")
xmllint --format input.xml > formatted.xml
xmllint --noblanks input.xml > minified.xml
| Tool | Primary purpose | Schema-aware |
|---|---|---|
| XML formatter | Readable or compact layout | No |
| XML validator | Syntax and well-formedness errors | Usually no |
| XSD validator | Contract and data-type validation | Yes |
| JSON formatter | JSON layout and syntax checks | No |
Use this formatter for quick browser-based cleanup. Use a project validator or CI check for production documents, namespaces, schemas, and security-sensitive parsing.
Formatting does not change the intended data model, but whitespace can be meaningful in mixed-content XML. Test documents containing human-readable text, xml:space="preserve", or CDATA in the target application.
This tool is provided for general informational and utility purposes only. Results may be inaccurate, incomplete, outdated, or contain errors. Always verify results before relying on or using them.
Some tools may use AI, automated processing, third-party services, or server-side processing. Do not rely on these tools as a substitute for professional advice.
Use at your own risk. BestToolOnline makes no guarantees regarding the accuracy, reliability, completeness, availability, or suitability of results, to the maximum extent permitted by applicable law.
See our Terms of Service and Privacy Policy for complete details.