PureDevTools

XML Formatter & Beautifier

Format, minify, and validate XML with syntax highlighting — all in your browser, nothing sent to any server

All processing happens in your browser. No data is sent to any server.
Indent:
Formatted Output

Formatted XML will appear here.

A SOAP API returns a 2000-character single-line XML response. You need to read the nested elements, check attribute values, and find the error code buried in <fault><faultcode>. Without indentation, XML is a wall of angle brackets that’s nearly impossible to navigate.

Why This Formatter (Not the XML to JSON Converter)

PureDevTools has an XML to JSON Converter for transforming XML data to JSON format. This tool formats XML — with proper indentation, syntax highlighting, error detection with line numbers, and a minify option. Use this formatter to read and clean up XML; use the converter when you need the data in JSON format.

What Is an XML Formatter?

An XML formatter — also called an XML beautifier, XML pretty printer, or XML indenter — takes XML that is compressed onto a single line or has inconsistent indentation and reformats it with clean, hierarchical indentation that mirrors the document’s element tree. Whether you received minified XML from an API, copied it from a log file, or generated it programmatically, an XML formatter makes it immediately readable and debuggable.

This tool supports:

XML Beautifier vs XML Minifier

These are opposite operations serving different purposes:

XML beautifier (the Format button) expands compact XML with newlines and consistent indentation. It reveals the tree structure at a glance — which elements are siblings, which are children, and how deeply nested the document is. Use it during development, debugging, API response inspection, and documentation.

XML minifier (the Minify button) strips all inter-element whitespace and XML comments, producing the most compact valid XML string. This is useful for reducing payload size in API requests and responses, storing XML in databases, and embedding XML snippets in code.

Example — the same document before and after formatting:

<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer Guide</title><price>44.95</price></book></catalog>

After formatting with 2-space indentation:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer Guide</title>
    <price>44.95</price>
  </book>
</catalog>

XML Validation

The built-in validator checks structural correctness before formatting:

CheckWhat It Detects
Tag matchingEvery opening <tag> has a matching </tag>
Tag nestingTags close in the correct order (no overlap like <a><b></a></b>)
Close tag without open</tag> with no corresponding opening tag
Unclosed open tag<tag> that is never closed

These checks catch the most common XML errors. Note that this is a structural validator — it does not validate against a DTD or XML Schema (XSD).

Syntax Highlighting

The output panel applies color-coded highlighting to all XML constructs:

TokenColorExamples
Element namesBlue<catalog>, </book>, <br/>
Attribute namesGreenid=, class=, version=
Attribute valuesOrange"bk101", "UTF-8", 'active'
Text contentDefaultEverything between element tags
CommentsGray (italic)<!-- This is a comment -->
CDATA sectionsPurple<![CDATA[raw content here]]>
Processing instructionsTeal<?xml version="1.0"?>, <?xml-stylesheet?>
EntitiesRed-orange&amp;, &lt;, &gt;, &#160;

XML Structure Reference

Elements are the core building blocks: <element>content</element> or self-closing <element/>. Element names are case-sensitive — <Item> and <item> are different elements.

Attributes provide metadata on elements: <book id="bk101" lang="en">. Attribute values must be quoted (single or double quotes). The same attribute name cannot appear twice on the same element.

Processing instructions (<?...?>) pass instructions to the XML processor. The XML declaration <?xml version="1.0" encoding="UTF-8"?> is the most common example. It must appear as the very first line of the document.

Comments (<!-- ... -->) can appear anywhere in the document except inside element tags and before the XML declaration. Comments are stripped by the minifier and preserved by the formatter.

CDATA sections (<![CDATA[...]]>) let you embed raw text that contains characters like < and & without escaping. They are preserved exactly as-is by both the formatter and minifier.

Entity references encode special characters: &lt; for <, &gt; for >, &amp; for &, &quot; for ", and &apos; for '. Numeric references like &#160; and &#xA0; are also valid.

Common Use Cases

API response debugging: REST and SOAP APIs often return compressed XML. Paste the response here to see its structure and identify unexpected nesting or missing fields.

Configuration file editing: XML configuration files (Maven pom.xml, Spring applicationContext.xml, Android AndroidManifest.xml, .NET app.config) are much easier to review and edit when properly formatted.

Data interchange inspection: RSS/Atom feeds, SVG files, XHTML documents, and data export files from enterprise systems often arrive minified. Format them before trying to understand or modify them.

XML Schema and DTD development: When writing XSD schemas, seeing the XML document properly indented helps verify that the schema correctly constrains the document structure.

XML Best Practices

Frequently Asked Questions

Does this formatter support all XML dialects? Yes. The formatter handles standard XML 1.0 including processing instructions, DOCTYPE declarations, CDATA sections, namespace prefixes (<ns:element xmlns:ns="...">), and entity references. SVG, XHTML, RSS, Atom, SOAP, and any other XML-based format will format correctly as long as the document is structurally valid XML.

What is the difference between XML and HTML? HTML is designed for displaying content in browsers and has looser parsing rules (self-closing tags are optional, attribute values can be unquoted). XML is a strict data format where every opening tag must have a matching closing tag, all attribute values must be quoted, and tag names are case-sensitive. XHTML is HTML written to XML rules.

Why does my XML show a validation error even though my XML editor says it’s fine? This tool performs structural validation (tag matching and nesting). If your XML is valid structurally but references a DTD or namespace that defines additional constraints, those constraints are not checked here. Also ensure that entity references use a declared DTD or are one of the five predefined XML entities (&lt;, &gt;, &amp;, &quot;, &apos;).

Can I format very large XML files? All processing runs entirely in your browser. Files up to several megabytes will format without noticeable delay. For extremely large XML documents (10MB+), consider using a desktop XML editor like oXygen or Visual Studio Code with an XML extension.

Is my XML sent to a server? No. All formatting, minification, validation, and syntax highlighting runs entirely in your browser using JavaScript. No XML data is transmitted to any server. Your documents never leave your device.

What happens to CDATA sections when I minify? CDATA sections are preserved exactly as-is in the minified output. Only inter-element whitespace and XML comments are removed. This ensures that CDATA content (which may include characters like < and &) remains intact and parseable.

Related Tools

More Data Converter Tools