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.
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
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
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
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.
<products>
<Item>
<name>Widget</name>
</item>
</products> <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.
<query>price > 10 & stock > 0</query>
<query>price > 10 & stock > 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 ").
<product id=p01 label="It's a "widget"">
<product id="p01" label="It's a "widget"">
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.
<user><name>Alice</name></user> <user><name>Bob</name></user>
<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.
<?xml version="1.0" encoding="UTF-8"?> <!-- File is actually saved as UTF-16 -->
<?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.
<script><![CDATA[
if (a < b && b > c) { return true; }
<!-- ]]> is missing --> <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?
What does the Validate button check?
Does validation check against an XML Schema (XSD) or DTD?
What is the difference between Format (Beautify) and Minify?
Does formatting preserve XML comments and attributes?
How do I format XML with 4-space indentation instead of 2?
What XML version and encoding does this tool support?
What causes a 'well-formedness' error and how do I fix it?
Can I use this tool to format XHTML or SVG files?
How does this tool handle XML namespaces?
Is there a file size limit for XML input?
How do I convert XML to JSON or JSON to XML?
Related Tools
View all tools →Base64 Decoder & Encoder
Encoding & Formatting
Decode and encode Base64 online for free. Real-time conversion with full UTF-8 and emoji support. 100% private — runs in your browser. No signup needed.
CSV to JSON Converter
Encoding & Formatting
Convert CSV to JSON in your browser. RFC 4180, type inference, header row, big-int safe. 100% private, no upload.
JSON Diff & Compare
Encoding & Formatting
Compare two JSON files instantly in your browser. Side-by-side highlighting, RFC 6902 JSON Patch output, ignore noisy fields like timestamps and IDs. 100% private, no upload.
JSON Formatter & Validator
Encoding & Formatting
Format, validate and beautify JSON instantly in your browser. Free online tool with syntax validation, error detection, minify and one-click copy. 100% private.
JSON Schema Validator
Encoding & Formatting
Validate JSON against any JSON Schema instantly in your browser. Supports Draft 2020-12, 2019-09, and Draft-07 with path-precise error messages. 100% private — no upload, no account, free.
JSON to CSV Converter
Encoding & Formatting
Convert JSON to CSV in your browser. RFC 4180, Excel-EU, TSV, Pipe presets. Flatten nested or stringify. 100% private, no upload.