XML Formatter & Validator — Format and Validate XML in Your Browser
Format messy XML into readable indented code and validate against XML rules. Runs entirely in your browser — your XML data never leaves your device. Free.
XML is still everywhere — SOAP APIs, configuration files, Android manifests, Maven POMs, Microsoft Office formats (.docx, .xlsx), SVG files, RSS feeds. SimpleTools XML Formatter formats minified or poorly structured XML into clean, readable code and validates it against XML rules — all in your browser.
What the XML Formatter Does
Before formatting:
<?xml version="1.0" encoding="UTF-8"?><root><person id="1"><name>Alice</name><email>alice@example.com</email><roles><role>admin</role><role>user</role></roles></person></root>After formatting:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<person id="1">
<name>Alice</name>
<email>alice@example.com</email>
<roles>
<role>admin</role>
<role>user</role>
</roles>
</person>
</root>The structure is immediately clear — nesting levels, sibling elements, and attribute values are easy to read and review.
Features
- XML formatting/beautifying: Proper indentation with configurable indent size (2 spaces, 4 spaces, tabs)
- XML minification: Remove all non-essential whitespace for the most compact output
- XML validation: Checks for well-formedness (proper nesting, closed tags, valid characters)
- Syntax highlighting: Keywords, attribute names, values, and comments in different colours
- Error markers: Precise line and column numbers for validation errors
- XPath tester: Enter XPath expressions and see matching nodes highlighted (advanced feature)
- Convert to JSON: Convert simple XML structures to equivalent JSON
- Copy or download: Export formatted XML with one click
XML Validation Rules
The tool validates XML well-formedness — the XML specification’s core rules:
- Single root element: An XML document must have exactly one root element
- Properly nested tags:
<a><b></b></a>is valid;<a><b></a></b>is not - Closed tags: Every opening tag must have a matching closing tag (or use self-closing
<tag/>) - Attribute quoting: Attribute values must be quoted (
<tag attr="value">, not<tag attr=value>) - Reserved characters:
<,>, and&in content must be escaped as<,>,& - Case sensitivity: XML tags are case-sensitive —
<Name>and<name>are different elements - Valid declaration: If present, the XML declaration must be the first line
Privacy: XML Often Contains Sensitive Data
XML files processed in this tool might include:
- SOAP API request/response bodies with business transactions
- Configuration files with environment settings, database connections, or API credentials
- Android manifests with app structure and permissions
- Microsoft Office documents (which are ZIP archives of XML files)
- Data exports from CRM, ERP, or HR systems
Uploading these to a cloud-based XML formatter sends that data to a third-party server.
✅ Your XML never leaves your browser
✅ Works offline
✅ No account required
✅ Free for any document size
How It Works
The browser’s native DOMParser API parses and validates XML:
const parser = new DOMParser();
const doc = parser.parseFromString(xmlString, 'application/xml');
const parseError = doc.querySelector('parsererror');
if (parseError) {
// Validation failed — extract error message and location
const errorText = parseError.textContent;
} else {
// Valid XML — serialise with formatting
const serializer = new XMLSerializer();
const formatted = formatXML(doc); // custom indentation function
}The formatting function recursively walks the DOM tree, adding indentation based on node depth. The result is a well-formatted XML string identical in structure to the original.
How to Use the XML Formatter
- Visit simpletools.one/xml-formatter
- Paste your XML in the input panel (or upload an XML file)
- Click Format — the formatted XML appears in the output panel
- Any validation errors appear with line/column markers
- Toggle to Minify for compact output
- Click Copy or Download to save the result
Common XML Errors and Fixes
| Error | Cause | Fix |
|---|---|---|
Unexpected end of document | Missing closing tag | Add the missing </tag> |
The element type "X" must be terminated | Tag not closed | Close the tag or use <X/> |
Attribute "X" must be quoted | Unquoted attribute value | Add quotes: attr="value" |
Reference to undeclared entity | Unescaped & character | Replace & with & |
Extra content after the last element | Multiple root elements | Wrap in a single root element |
Format and validate your XML at simpletools.one/xml-formatter — private, instant, and completely free.