Skip to content

XML Formatter

Beautify, minify, and validate XML in-browser — nothing uploaded. Re-indents messy XML, reports well-formedness errors with line/column. Free, private, no signup.

No Tracking Runs in Browser Free
Indent
XML Output
Reviewed for XML 1.0 well-formedness compliance, lossless formatting, and accurate error reporting — Go Tools Engineering Team · May 29, 2026

What is an XML Formatter and Why Use One?

XML (Extensible Markup Language) is a text-based format for structured data, used everywhere from web services and configuration files to RSS feeds, SOAP APIs, office documents (DOCX, XLSX), SVG graphics, and Android layout files. Unlike JSON, XML supports comments, namespaces, mixed content (text and elements interleaved), and document-type declarations — making it the format of choice for enterprise integration, document exchange, and anywhere structured data needs to coexist with human-readable markup.

XML in the wild is often badly indented or completely minified — API responses arrive on a single line, config files accumulate inconsistent indentation, and generated XML from serializers adds no whitespace at all. An XML formatter takes that messy input and re-indents it into a clean, hierarchical structure where every level of nesting is visually clear. This is essential for code review, debugging, documentation, and understanding unfamiliar XML schemas.

**What this tool does differently from a plain text editor:**

**1. Well-formedness validation with precise error location.** The formatter uses the browser's DOMParser (the same engine that parses HTML and SVG) to parse the XML. If the document is not well-formed — mismatched tags, unclosed elements, unescaped characters, or multiple root elements — the parser reports the exact line and column number where it failed. This is far faster than reading raw XML looking for where a tag was accidentally left open.

**2. Lossless formatting.** The formatter preserves comments, processing instructions, CDATA sections, namespace declarations, attribute order, and all text content exactly. It only adjusts the whitespace between element tags. You can safely format any XML you care about — nothing meaningful will change.

**3. Minification for production use.** The minifier strips all insignificant inter-element whitespace, producing the smallest valid XML representation. This is the right preprocessing step before storing XML in a database column, inserting it as a string into JSON, or transmitting it over a byte-counted channel.

**4. 100% browser-based privacy.** Healthcare XML (HL7, FHIR), financial data, SOAP payloads with credentials, and internal configuration files are all common XML payloads that contain sensitive data. This tool never uploads anything — all processing runs in your browser's JavaScript engine. See our companion tools if you need to convert rather than format: XML to JSON Converter for converting XML to JSON, and JSON to XML Converter for the reverse direction.

<!-- Minified XML input -->
<?xml version="1.0" encoding="UTF-8"?><catalog><product id="p01"><name>Wireless Headphones</name><price currency="USD">79.99</price></product></catalog>

<!-- After formatting with 2-space indent -->
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <product id="p01">
    <name>Wireless Headphones</name>
    <price currency="USD">79.99</price>
  </product>
</catalog>

Key Features

Beautify with 2 or 4 Space Indent

Re-indents XML into a clean, readable hierarchy. Choose 2-space (most common for web services, RSS, and config files) or 4-space (common in enterprise XML schemas) indentation before formatting.

Minify — Strip Non-Significant Whitespace

Removes all whitespace between element tags without touching text content, producing the smallest valid XML. Ideal for storage, transmission, or embedding as a string inside JSON or other formats.

Well-Formedness Validation with Line/Column Errors

Uses the browser's built-in DOMParser to validate XML structure. Reports the exact line number and column of the first well-formedness error — mismatched tags, unclosed elements, unescaped characters — for fast debugging.

Lossless: Preserves Comments, Namespaces, and Attributes

Comments, processing instructions, CDATA sections, namespace declarations, and attribute order are all preserved exactly. Only insignificant whitespace between tags is modified — your content is never altered.

100% Browser-Based — No Upload, No Server

All processing runs locally in your browser. XML payloads containing credentials, healthcare data, financial records, or internal configs are never transmitted to any server and never logged.

Works with SOAP, RSS, SVG, XHTML, and Android XML

Handles any well-formed XML application: SOAP envelopes with WS-Security headers, RSS/Atom feeds, SVG files, XHTML documents, Android layout XMLs, Maven POMs, and Maven/Ant build files.

Examples

Messy / Minified XML

<?xml version="1.0" encoding="UTF-8"?><catalog><product id="p01" category="electronics"><name>Wireless Headphones</name><price currency="USD">79.99</price><stock>142</stock><tags><tag>audio</tag><tag>bluetooth</tag></tags></product><product id="p02" category="books"><name>Learning XML</name><price currency="USD">29.99</price><stock>55</stock></product></catalog>

A compact one-line XML product catalog. Click Format to indent it into a readable tree with 2-space indentation. The element hierarchy, attributes, and text content are all preserved exactly — formatting is purely cosmetic.

RSS Feed Snippet

<rss version="2.0"><channel><title>Go Tools Blog</title><link>https://go-tools.org/blog</link><description>Developer tools, tips and tutorials</description><item><title>Understanding XML Namespaces</title><link>https://go-tools.org/blog/xml-namespaces-guide</link><pubDate>Thu, 29 May 2026 00:00:00 GMT</pubDate><description>A deep dive into XML namespace declarations, prefixes, and scope rules with practical examples.</description></item><item><title>XML vs JSON: When to Use Each</title><link>https://go-tools.org/blog/xml-vs-json</link><pubDate>Mon, 25 May 2026 00:00:00 GMT</pubDate></item></channel></rss>

A two-item RSS 2.0 feed compressed onto one line. After formatting, the channel metadata and each item element appear clearly indented, making it easy to inspect feed structure, add new items, or compare against a feed validator's requirements.

SOAP Envelope

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>api-client</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-ext-1.0.xsd#PasswordText">s3cr3t</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header><soap:Body><GetOrderRequest xmlns="http://example.com/orders"><OrderId>ORD-20260529-001</OrderId><IncludeLineItems>true</IncludeLineItems></GetOrderRequest></soap:Body></soap:Envelope>

A SOAP 1.1 envelope with a WS-Security header and a GetOrder body, using three namespace prefixes (soap:, wsse:, and default). Formatting makes the header/body separation and namespace declarations immediately clear — essential for debugging SOAP integrations and reading WSDL-generated payloads.

How to Use

  1. 1

    Paste Your XML

    Enter or paste your XML into the input field above. You can also click 'Load example' to try a sample (a minified product catalog XML that formats nicely).

  2. 2

    Choose an Action

    Click Format to beautify with indentation, Minify to strip whitespace, or Validate to check well-formedness. Select 2 or 4 spaces for the indent size before formatting.

  3. 3

    Copy the Output

    The processed XML appears in the output panel. Click Copy to grab it to your clipboard. If Validate found errors, the error banner shows the exact line and column number.

Common XML Errors

Mismatched Tags

XML tag names are case-sensitive and must match exactly. and are different tags — XML sees this as an unclosed element and a stray . This is the most frequent cause of well-formedness errors when hand-editing XML.

✗ Wrong
<products>
  <Item>
    <name>Widget</name>
  </item>
</products>
✓ Correct
<products>
  <item>
    <name>Widget</name>
  </item>
</products>

Unescaped Ampersand or Less-Than Sign

The characters & and < are reserved in XML and must be escaped outside of CDATA sections. A bare & causes a parser error even in attribute values. Use & for & and < for <. The greater-than sign > should be escaped as > in text content, though parsers are more lenient about it.

✗ Wrong
<query>price > 10 & stock > 0</query>
✓ Correct
<query>price &gt; 10 &amp; stock &gt; 0</query>

Unquoted or Improperly Quoted Attributes

All XML attribute values must be enclosed in either single or double quotes. Unquoted attribute values are valid in HTML5 but are a well-formedness error in XML. Also, a value containing a double quote must use single quotes as delimiters (or escape the quote as ").

✗ Wrong
<product id=p01 label="It's a "widget"">
✓ Correct
<product id="p01" label="It's a &quot;widget&quot;">

Multiple Root Elements

An XML document must have exactly one root element that contains all other elements. A common mistake when stitching together XML fragments is ending up with two or more top-level elements side by side, which is not valid XML (though it is common in HTML). Wrap all sibling elements in a single root container.

✗ Wrong
<user><name>Alice</name></user>
<user><name>Bob</name></user>
✓ Correct
<users>
  <user><name>Alice</name></user>
  <user><name>Bob</name></user>
</users>

Missing XML Declaration Encoding Mismatch

If your XML file is saved in UTF-16 or another non-UTF-8 encoding but the declaration says encoding="UTF-8" (or is absent, which defaults to UTF-8), some parsers will reject it or produce garbage. When pasting into a browser-based tool, the browser handles encoding automatically. For files on disk, ensure the encoding attribute matches the actual file encoding.

✗ Wrong
<?xml version="1.0" encoding="UTF-8"?>
<!-- File is actually saved as UTF-16 -->
✓ Correct
<?xml version="1.0" encoding="UTF-16"?>
<!-- File saved as UTF-16, declaration matches -->

CDATA Section Not Properly Closed

A CDATA section starts with . If the ]]> closing sequence is missing or mistyped, the parser treats everything that follows as part of the CDATA section until it finds another ]]> or hits the end of the document. This typically manifests as 'unexpected end of document' errors.

✗ Wrong
<script><![CDATA[
  if (a < b && b > c) { return true; }
<!-- ]]> is missing -->
✓ Correct
<script><![CDATA[
  if (a < b && b > c) { return true; }
]]></script>

Common Use Cases

Debugging SOAP / Web Service Payloads
SOAP responses from enterprise APIs and legacy web services arrive as single-line XML strings. Paste the raw payload into the formatter to instantly see the envelope structure, headers, and body — making it easy to find the field you need or spot a namespace mismatch. See also: XML to JSON Converter if you need to process the payload further in JavaScript.
Validating Config Files and Deployment Descriptors
Maven POM files, Spring XML application contexts, Tomcat server.xml, Android Manifest files, and many other Java/enterprise configuration files are XML. Run them through Validate before committing to catch mismatched tags or encoding issues that would otherwise only surface at build or deploy time.
Formatting RSS and Atom Feed Output
RSS 2.0 and Atom 1.0 feeds are XML. When developing a feed generator or debugging feed reader compatibility issues, format the raw feed XML to inspect the channel metadata, item structure, and required namespace declarations side by side.
Reading and Editing SVG Files
SVG files exported from Figma, Illustrator, or Sketch are valid XML but are often minified or contain excessive indentation from the exporter. Format the SVG to get a clean, navigable element tree before making manual edits to paths, groups, or styling attributes.
Preparing XML for Storage or Transmission
When storing XML in a database column, sending it as a JSON string field in an API request, or inserting it into a message queue, use Minify first to strip unnecessary whitespace. This reduces payload size and avoids issues with JSON parsers that may choke on unescaped control characters in large indented XML strings.
Converting XML to JSON
If you need to convert your formatted XML to JSON for use in a JavaScript application or REST API, use our XML to JSON Converter. For the reverse — building XML from a JSON structure — use the JSON to XML Converter.

Technical Details

Browser DOMParser for XML Parsing
XML parsing uses the browser's native DOMParser with the 'text/xml' MIME type. This is the same engine that powers SVG and XHTML rendering in the browser — it is fully XML 1.0 compliant and reports well-formedness errors with line and column information. When the document is not well-formed, DOMParser returns a parsererror document containing the error message and position, which this tool extracts and displays.
DOM Tree Serialization for Formatting
Formatting works by parsing the XML into a DOM tree and then walking the tree recursively to produce indented output. This approach preserves the semantic structure of the document: element nesting, text content, attributes, CDATA sections, processing instructions, and comments are all serialized back exactly as parsed. Only inter-element whitespace-only text nodes are discarded — text nodes that contain non-whitespace characters are always preserved.
Minification via Whitespace-Only Text Node Removal
Minification traverses the same DOM tree and removes text nodes whose content is entirely whitespace (spaces, tabs, newlines). Text nodes with mixed or non-whitespace content — the actual data between tags — are never removed. Attributes and their values are serialized without added whitespace. The result is the most compact well-formed XML representation of the original document.
100% Browser-Based — No Upload, No Server
All processing runs in your browser's JavaScript runtime. No data is transmitted to any server at any point. This is especially important for XML payloads that frequently contain sensitive content: SOAP WS-Security tokens, HL7 patient data, internal service configuration, and financial message formats (FIX, SWIFT ISO 20022). The tool is safe to use with any XML that you would not want to paste into a public service.

Best Practices

Validate Before Formatting, Format Before Committing
Validate your XML first to confirm it is well-formed before reformatting — the formatter will silently produce incorrect output if the input is not valid XML. Once validated, format and review the indented output before committing config files, feed templates, or WSDL definitions to version control.
Use 2-Space Indent for Web Formats, 4-Space for Enterprise XML
Two-space indentation is the convention for RSS/Atom feeds, SVG, XHTML, Android XML, and most web-facing XML. Four-space indentation is common in Java enterprise environments (Maven POM, Spring context files, JBoss deployment descriptors). Match the convention of your existing files and toolchain.
Minify XML Before Embedding in JSON
If you need to embed an XML string as a JSON field value, always minify it first. Indented XML contains newlines and multiple spaces that must be JSON-escaped (\n, multiple \u0020), dramatically inflating payload size. Minified XML is also far less likely to trigger line-length limits in intermediary proxies or logging systems.
Escape Special Characters in Text Content, Use CDATA Sparingly
For short text values containing & or <, use entity references (&, <) — they are more portable than CDATA sections and work in attribute values too. Reserve CDATA sections () for embedding large blocks of code, SQL queries, or HTML fragments where escaping every special character would make the content unreadable.
Declare Namespaces as Early as Possible
Declare XML namespaces (xmlns:prefix="URI") on the root element or the highest-level element that uses the prefix. Declaring namespaces deep in a document tree makes the XML harder to read and can cause issues with stream-based XML parsers (SAX, StAX) that process namespaces incrementally. The SOAP Envelope example above demonstrates the recommended pattern: all namespace declarations on the root Envelope element.

Frequently Asked Questions

Is my XML data sent to a server when I use this tool?
No. All formatting, minification, and validation happens entirely inside your browser using JavaScript. Your XML is never transmitted over the network, never stored on any server, and never logged or analyzed by anyone. This makes the tool safe to use with XML payloads that contain API credentials, internal service data, financial records, healthcare HL7/FHIR documents, or any other sensitive content. You can confirm this by opening your browser's Network tab — you will see zero requests triggered by pasting or processing XML.
What does the Validate button check?
The Validate button checks whether your XML is well-formed according to the XML 1.0 specification. Well-formedness means: every opening tag has a matching closing tag, tags are properly nested (no overlapping elements), the document has exactly one root element, attribute values are quoted, and reserved characters (&, <, >) are properly escaped as &, <, and >. When the XML is well-formed, a green 'Valid XML' banner appears. When it is not, an error message appears with the line number and column number where the problem was found, so you can locate and fix the issue immediately.
Does validation check against an XML Schema (XSD) or DTD?
No. This tool checks well-formedness only — it does not validate against an XSD schema, a DTD, a RELAX NG schema, or any other grammar. Well-formedness is a precondition for schema validation, but they are different levels of correctness. An XML document can be perfectly well-formed but still violate a schema (for example, a required element is missing, or a numeric field contains a string). For full schema validation you need a tool like xmllint (command-line), Oxygen XML Editor, or your programming language's XML parser with schema support enabled.
What is the difference between Format (Beautify) and Minify?
Format (Beautify) adds consistent indentation and newlines to make XML human-readable. Each nested element is indented by the selected number of spaces (2 or 4), so the hierarchical structure is immediately visible. This is what you want when reading, editing, or diffing XML. Minify does the opposite: it removes all whitespace that is not part of element text content, collapsing the document to the minimum number of characters. This is useful before storing XML in a database, transmitting it over a network where byte count matters, or embedding it as a string in another format. Both operations produce semantically identical XML — only the non-significant whitespace changes.
Does formatting preserve XML comments and attributes?
Yes. Formatting is completely lossless with respect to XML content. Comments () are preserved in place with their surrounding whitespace adjusted for indentation. All attributes, their order within a tag, and their values are preserved exactly. CDATA sections, processing instructions (), and namespace declarations are also preserved. The formatter only adjusts the whitespace between element tags — it never modifies element names, attribute names, attribute values, text content, or comments.
How do I format XML with 4-space indentation instead of 2?
Click the '4 spaces' radio button in the Indent control (next to the Format, Minify, and Validate buttons), then click Format. The output panel will re-render the XML with 4-space indentation. You can switch between 2 and 4 spaces at any time and click Format again — the indentation size is read at the time you click the button. Two-space indentation is the most common convention in web services and data exchange formats; four-space indentation is sometimes preferred in enterprise XML schemas and SOAP-heavy environments.
What XML version and encoding does this tool support?
The formatter uses the browser's built-in DOMParser with the text/xml MIME type, which supports XML 1.0 documents in any character encoding that the browser can handle — in practice, UTF-8, UTF-16, and ISO-8859-1 cover virtually all real-world XML. The XML declaration () is preserved if present. For XML 1.1 documents (rare in practice, mainly used for Unicode control characters), the same parser applies but some XML 1.1-specific features may not be fully enforced.
What causes a 'well-formedness' error and how do I fix it?
The most common well-formedness errors are: (1) Mismatched tags — an opening tag like with a closing tag like (note the plural). Fix: match tag names exactly, including case. (2) Unclosed tags — a tag that never has a corresponding close tag or self-closing slash. Fix: add the closing tag or change to . (3) Unescaped special characters — using & directly in text content instead of &, or < instead of <. Fix: replace bare & with & and bare < with < outside CDATA sections. (4) Multiple root elements — XML requires exactly one root element wrapping everything else. Fix: wrap all content in a single root tag. The error message from this tool includes the line and column number of the first problem found.
Can I use this tool to format XHTML or SVG files?
Yes. XHTML and SVG are both valid XML applications, so this tool formats, minifies, and validates them correctly. For XHTML, it will catch mismatched or unclosed tags that would be silently ignored in HTML5 parsers but are errors in strict XHTML. For SVG, it is particularly useful for formatting complex path-heavy files generated by tools like Figma or Illustrator, making it easier to inspect or edit the element structure manually.
How does this tool handle XML namespaces?
XML namespaces (xmlns declarations, namespace prefixes like soap:, xsi:, and so on) are fully preserved by the formatter. The namespace declarations remain on the element where they were originally declared and are not moved or deduplicated. Namespace-prefixed element names and attribute names are treated as opaque strings by the formatter — the prefix and local name are preserved exactly as written. The SOAP Envelope example above demonstrates a document with three namespace prefixes.
Is there a file size limit for XML input?
There is no hard size limit enforced by the tool, but the browser's DOM-based parser will consume memory proportional to the document size. For most real-world XML files (configuration files, API responses, RSS feeds, SOAP payloads) well under 1MB, performance is instant. For very large XML files — multi-megabyte data exports or log files — consider using a command-line tool instead: xmllint --format input.xml on Linux/macOS (part of libxml2), or python3 -c "import xml.dom.minidom; print(xml.dom.minidom.parse('input.xml').toprettyxml(indent=' '))" as a cross-platform option.
How do I convert XML to JSON or JSON to XML?
This tool focuses on formatting and validating XML structure. To convert between XML and JSON, use the companion tools: XML to JSON Converter converts XML documents to their JSON representation, and JSON to XML Converter converts JSON objects to XML. Both tools are also 100% browser-based with no data upload.

Related Tools

View all tools →