🧠 Built by SuperML.dev · SuperML.org

Having issues with buttons or file uploads? If tools aren't responding, please or press Ctrl+F5 (or Cmd+R on Mac).

← Back to Blog

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:

  1. Single root element: An XML document must have exactly one root element
  2. Properly nested tags: <a><b></b></a> is valid; <a><b></a></b> is not
  3. Closed tags: Every opening tag must have a matching closing tag (or use self-closing <tag/>)
  4. Attribute quoting: Attribute values must be quoted (<tag attr="value">, not <tag attr=value>)
  5. Reserved characters: <, >, and & in content must be escaped as &lt;, &gt;, &amp;
  6. Case sensitivity: XML tags are case-sensitive — <Name> and <name> are different elements
  7. 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.

SimpleTools XML Formatter:

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

  1. Visit simpletools.one/xml-formatter
  2. Paste your XML in the input panel (or upload an XML file)
  3. Click Format — the formatted XML appears in the output panel
  4. Any validation errors appear with line/column markers
  5. Toggle to Minify for compact output
  6. Click Copy or Download to save the result

Common XML Errors and Fixes

ErrorCauseFix
Unexpected end of documentMissing closing tagAdd the missing </tag>
The element type "X" must be terminatedTag not closedClose the tag or use <X/>
Attribute "X" must be quotedUnquoted attribute valueAdd quotes: attr="value"
Reference to undeclared entityUnescaped & characterReplace & with &amp;
Extra content after the last elementMultiple root elementsWrap in a single root element

Format and validate your XML at simpletools.one/xml-formatter — private, instant, and completely free.

Enjoyed this post?

Subscribe to our newsletter or explore more privacy-friendly tools!

Explore Tools