ToolBook
Support us on Ko-fi
Help us keep this free, forever

XML Formatter & Validator

How to format and validate XML online

Pretty-print, validate, or minify any XML document in seconds using ToolBook.

  1. Paste or upload your XML

    Click the input area and paste your XML, or click "Upload file" to load a local .xml, .svg, .xsd, or .wsdl file directly from your computer.

  2. Choose an indent style

    Select 2 spaces, 4 spaces, Tab, or Minify from the toolbar. The output updates instantly as you switch between options.

  3. Fix any validation errors

    If the XML is not well-formed, a red error banner appears with the location and reason. Correct the input and the error clears automatically.

  4. Copy or download the result

    Click Copy to copy the formatted XML to your clipboard, or click Download to save it as a .xml file to your computer.

Frequently asked questions

What is XML and when do developers still use it?

XML (Extensible Markup Language) is a structured text format used in many industries. Developers encounter it in SOAP web services, Android resource files (layouts, strings, manifests), Maven pom.xml, Spring configuration, RSS/Atom feeds, SVG images, XLSX/DOCX file internals, and enterprise systems in banking and healthcare.

What is the difference between formatting and validating XML?

Formatting rewrites the XML with consistent indentation for readability. Validation checks that the XML is well-formed: all tags are properly closed, attributes are quoted, and there is exactly one root element. This tool validates well-formedness. Full XML Schema (XSD) or DTD validation requires a schema file.

What are the most common XML syntax errors?

The most frequent XML errors are: unclosed tags (forgetting </tag>), mismatched opening and closing tag names, unquoted attribute values (use attr="value" not attr=value), bare & or < characters in text content that must be written as &amp; and &lt;, and documents with more than one root element. The validator flags the first error it encounters with its approximate location.

What are self-closing tags in XML?

An element with no content can be written as <item/> instead of <item></item>. This is called a self-closing or empty element. In HTML, only void elements (br, img, input) are self-closing. In XML, any element can use the self-closing form; the two notations are semantically identical.

What is CDATA and when should I use it?

A CDATA section (<![CDATA[...]]>) lets you embed raw text that contains characters such as < and & without entity-encoding them. Everything between the markers is treated as literal text, not XML markup. CDATA is useful for embedding HTML snippets, SQL, or JavaScript inside an XML document.

When should I minify XML?

Minify XML before storing it in a database, sending it over a network API, or packaging it inside a binary archive (like a .docx or .xlsx file). Minification removes insignificant whitespace between elements, typically reducing file size by 20 to 40%. The XML stays semantically identical, so any parser, XPath query, or XSLT transform produces the same result from minified XML.

Can I upload an XML file instead of pasting?

Yes. Click the "Upload file" button in the input panel and select any .xml, .xhtml, .svg, .xsl, .xsd, .wsdl, or .pom file from your computer. The file is read locally and never leaves your browser. File contents appear in the input area and format automatically.

Does this XML formatter send my data to a server?

No. All formatting, validation, and minification runs entirely in your browser using built-in JavaScript APIs. Nothing is transmitted to any server. This makes the tool safe for confidential configuration files, internal API payloads, and sensitive enterprise data.

What is the difference between XML well-formedness and XML validity?

A well-formed XML document follows the basic syntax rules of XML: properly nested tags, exactly one root element, quoted attribute values, and correct character encoding. A valid XML document additionally conforms to a specific schema (either a DTD or XSD file) that defines allowed elements, attributes, and nesting rules. This tool checks well-formedness only. Schema validation requires uploading or referencing the schema file.

XML formatting and validation: the complete guide

From angle brackets to document trees — what every developer should know about working with XML.

What is XML and where is it still used?

XML (Extensible Markup Language) was the dominant data exchange format of the 2000s. While JSON has replaced it in most web API contexts, XML remains ubiquitous in:

  • Enterprise integrations: SOAP web services, EDI, SAP, and most ERP systems still use XML heavily.
  • Android resources: Layout files, strings, and manifests are all XML.
  • Microsoft Office formats: DOCX, XLSX, and PPTX are ZIP archives containing XML files.
  • SVG images: SVG is XML. Every icon set and vector graphic on the web is an XML document.
  • RSS and Atom feeds: Still widely used for content syndication.
  • Maven, Ant, and build tools: Java ecosystem build files are XML.
  • Configuration files: Spring (Java), .NET config files, and many IDE settings are XML.

XML structure: the key concepts

An XML document is a tree of elements, each with an opening tag, optional attributes, content, and a closing tag. The document must have exactly one root element.

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <element attribute="value">text content</element>
  <self-closing />
</root>

Key structural rules:

  • Well-formed: Tags are properly nested and closed. Every attribute value is quoted.
  • Valid: The document conforms to a schema (DTD or XSD). The formatter checks well-formedness but not schema validity.
  • Case-sensitive: <Element> and <element> are different tags.

Special XML syntax

The formatter handles four special token types beyond regular elements:

  • **Processing instructions (<?...?>): Directives to the XML processor, including the XML declaration at the top (<?xml version="1.0"?>).
  • Comments (<!-- ... -->): Preserved in formatted output, stripped in minified output.
  • CDATA sections (<![CDATA[...]]>): Raw text that should not be parsed as XML. Used to embed HTML or scripts in XML documents.
  • DTD declarations (<!DOCTYPE...>): Treated as a single token and preserved as-is.

Attribute values and encoding

XML has five predefined character entities that must be escaped in attribute values and text content:

  • &amp;&
  • &lt;<
  • &gt;>
  • &quot;"
  • &apos;'

The formatter preserves these entities as-is — it does not decode and re-encode them, so well-formed entities in the input remain well-formed in the output.

Minification savings

XML is verbose by design — tag names repeat in opening and closing tags, attribute names are unabbreviated, and there's no shorthand for empty values. Minification removes all whitespace between tags, producing the smallest possible valid XML document. For average XML documents, minification saves 20–40%. For XML with many short element names and attributes, savings are smaller; for XML with long text nodes between tags, savings can exceed 50%.

XPath and querying minified XML

Minified XML is semantically identical to formatted XML — any XPath query, XSLT transform, or DOM parser will produce the same result from both. Minification only removes insignificant whitespace (whitespace between elements). Whitespace that is significant — like whitespace inside text nodes — is preserved.