XML Formatter
Format, minify and validate XML instantly
๐ No upload โ runs entirely in your browser. Your XML never leaves your device.
Related Tools
JSON Formatter
Format, minify and validate JSON with error detection.
YAML Formatter & Validator
Format, validate and convert YAML. Pretty-print and detect syntax errors.
HTML Formatter & Beautifier
Format, beautify and minify HTML with clean indentation.
SQL Formatter
Format, beautify and minify SQL queries online.
CSV to JSON Converter
Convert CSV to JSON and JSON to CSV with delimiter options.
What is the XML Formatter?
The XML Formatter beautifies minified or compressed XML into a readable, properly indented structure โ and validates it for syntax errors at the same time. It also minifies formatted XML back to a single line for compact transmission. XML (Extensible Markup Language) remains the standard data format for SOAP web services, Android resources, Maven build files, SVG graphics, Office Open XML documents (DOCX, XLSX), RSS and Atom feeds, and countless enterprise configuration systems. Paste API payloads, config files, or any XML string to instantly see its structure and catch missing closing tags, unquoted attributes, or illegal characters.
The formatter works entirely in your browser using the browser's native DOMParser and no data is ever sent to a server. It supports both 2-space and 4-space indentation, preserves XML declarations and processing instructions, and handles namespaced elements like soap:Envelope and xsi:type correctly.
How to Use the XML Formatter
- 1.Paste your XML string into the left input panel โ it can be minified, multi-line, or partially formatted.
- 2.Click Format to pretty-print with 2 or 4 space indentation, Minify to collapse to one line, or Validate to check well-formedness without changing format.
- 3.If the XML is invalid, a red error panel shows the parser's error message describing the problem and its location.
- 4.Click the Copy button in the output panel header to copy the formatted or minified result to your clipboard.
- 5.Click Clear โ to remove all input and start fresh with a new XML string.
Example: copy a SOAP response body from Charles Proxy, Postman, or your browser's DevTools Network tab, paste it here, click Format, and instantly read the nested envelope structure โ useful when debugging which SOAP fault element caused a service failure in your integration.
Real-World Use Cases
1. Debugging SOAP Web Service Responses
Enterprise integrations frequently use SOAP, which wraps data in verbose XML envelopes. A typical SOAP fault response minified by a server looks like a single line of hundreds of characters. Paste it into the formatter to unfold the soap:Fault structure and read the faultcode, faultstring, and detail elements at a glance. The formatter correctly handles SOAP namespace prefixes like soap:, xsi:, and tns: without stripping them.
2. Editing Android Resource Files
Android apps rely heavily on XML: AndroidManifest.xml, layout files, string resources, and menu definitions. When copying XML snippets from Stack Overflow or documentation, the indentation often becomes inconsistent. Paste the snippet here to normalize it before adding it to your project. For strings.xml, the validate mode will catch character encoding issues before your Gradle build fails.
3. Reviewing Maven pom.xml and Spring Configuration
Java projects use XML extensively โ Maven pom.xml files define all project dependencies and build plugins, while Spring XML configuration files wire together application beans. These files can grow to hundreds of lines and are easy to corrupt accidentally when merging branches. The validator immediately flags unclosed tags and malformed attribute values before you push to CI, saving a cycle of failing builds.
4. Working with RSS and Atom Feeds
RSS 2.0 and Atom 1.0 feeds are XML documents that content aggregators and podcast players consume. Feed validation matters because a single malformed entry can break the entire feed for subscribers. Paste your feed XML here to check well-formedness and pretty-print it for review before publishing. The formatter preserves CDATA sections used in descriptions and correctly handles the xmlns namespace declarations in Atom feeds.
Common XML Errors and How to Fix Them
The validator shows the exact error from the browser's XML parser. Here are the most frequent XML well-formedness errors and their fixes.
- Unclosed tag. Every element opened with
<tag>must be closed with</tag>or collapsed to<tag/>. This is the most common error when migrating from HTML to XML โ HTML parsers are forgiving about unclosed<br>and<img>; XML is not. - Unquoted attribute value. All XML attribute values must be enclosed in double or single quotes:
width=100must becomewidth="100". - Unescaped ampersand or angle bracket. In text content and attribute values,
&must be written as&,<as<, and>as>. Raw&is especially common in URLs inside href attributes. - Improperly nested tags. Tags must be closed in the reverse order they were opened.
<a><b></a></b>is invalid; it must be<a><b></b></a>. - Multiple root elements. An XML document must have exactly one root element. If your document has two top-level elements, wrap them in a single container element.
- Illegal characters in names. Element and attribute names must start with a letter, underscore, or colon (for namespaces). Names cannot contain spaces or start with a digit.
<2cool>is invalid; rename it to<_2cool>or<twocool>.
XML vs JSON: When to Use Each
Both XML and JSON are text-based data interchange formats, but they excel in different situations:
- Choose XML when: you need document-centric data with mixed content (text interleaved with elements), metadata on elements via attributes, namespaces to combine vocabularies, or schema validation via DTD or XSD. XML is also required for SOAP, SVG, Office Open XML, and many legacy enterprise APIs.
- Choose JSON when: you are building a REST API consumed by JavaScript clients, the data is purely object/array structured without mixed content, or you want smaller payloads and faster parsing. JSON has no equivalent to XML attributes, namespaces, or comments, which simplifies schemas but limits expressiveness.
- In practice today: new public APIs almost universally use JSON. XML dominates in enterprise integration layers (EDI, financial messaging, government systems), document formats (DOCX, EPUB, SVG), and build tooling (Maven, Gradle, Ant). Many systems support both formats with a
Content-Type: application/xmlorapplication/jsonheader switch.