XML Formatter
Pretty-print, minify, and validate XML on the spot — check for well-formedness errors instantly. Also handy for inspecting SOAP/REST API responses and RSS/Atom feeds.
What is the XML Formatter?
The XML Formatter takes a single unbroken line of XML — or XML with inconsistent indentation — and re-formats it into a readable, indented structure. It can also do the opposite: strip the whitespace and line breaks between tags to compress everything onto one line (minify mode), and you can switch between the two with a single toggle. Indentation can be set to 2 spaces, 4 spaces, or a tab, so the output matches whatever convention your project already follows.
As you type, the tool also checks in real time whether every opening tag has a matching closing tag and whether the nesting is intact — in other words, whether the document is well-formed. If something is broken, an "Invalid XML" badge appears along with a line-by-line list of exactly where each error occurred, so you don't have to scan the whole document by eye. Everything runs entirely in JavaScript inside your browser; the XML you paste in is never sent to toolbase.cc's servers.
How to use the XML Formatter
- Paste in your XML Paste your XML into the input box on the left. If you don't have a sample handy, click "Sample" to load an example RSS feed.
- Choose an indent width Pick 2 spaces, 4 spaces, or a tab. Matching your existing file's convention means you can paste the result straight back in without extra cleanup.
- Check the formatted output and badge The formatted result appears on the right, along with a "Well-formed" or "Invalid XML" badge. If it's invalid, a list of errors with line numbers appears below.
- Switch to minify mode if needed Turning on "Minify mode" changes the output box to show the compressed, single-line version with the whitespace between tags removed.
- Copy the formatted or minified version Click "Copy formatted" or "Copy minified" to send the corresponding result to your clipboard.
Tips for getting more out of it
- Everything you type is processed entirely in your browser with JavaScript — nothing is ever sent to toolbase.cc's servers, so it's safe to format internal config files or responses containing sensitive data.
- Turning on minify mode strips all whitespace and line breaks between tags, which is handy for embedding XML into config files or shrinking an HTTP request body.
- If the output shows "Invalid XML," it's usually caused by an unclosed tag or a mismatch between an opening and closing tag name. Use the line number shown in the error list to track down the problem.
- This tool is a sibling of the JSON and SQL formatters, built on the same approach. If your API returns both JSON and XML, pairing this with the JSON Formatter can speed up debugging.
- Tag matching also accounts for namespace prefixes (e.g.
<soap:Envelope>), so this works well for debugging SOAP messages too.
Ways to use the XML Formatter
Reading SOAP/REST API responses
When a SOAP or REST endpoint returns XML squeezed onto one line, formatting it lets you follow the element nesting and namespace prefixes at a glance — handy while debugging during development.
Reading RSS/Atom feeds
Format the RSS/Atom feed a blog or news site publishes so you can inspect the order of its item elements and the value of each field in a human-readable layout.
Tracking down syntax errors in config files and build definitions
When an Android layout XML or a Maven pom.xml won't load, paste it in and validate it to spot an unclosed tag on the spot.
Minifying to cut down transfer size
Serving a pretty-printed XML file as-is over an API response or static asset adds extra bytes for every space of indentation. Use the minified version for anything that gets served to real users.
Prepping XML before converting it to another format
Confirming a document is well-formed first means tools like XML to JSON won't choke on it with a confusing error that's hard to trace back to the source.
XML glossary
- Element
- The basic building block of an XML document, made up of an opening and closing tag (
<item>...</item>) or a self-closing tag (<item />). Elements can nest inside one another, and a whole document forms a tree under a single root element. - Attribute
- Extra information written inside an opening tag as
name="value". Whether to model a piece of data as a child element or as an attribute is a design decision, and XML Schema design guides discuss the trade-offs at length. - Well-formed
- A mandatory requirement of the XML spec stating that every tag opens and closes correctly with no broken nesting. This tool's validation checks exactly this property. It's a separate concept from "valid," which refers to conforming to a schema.
- Namespace
- A mechanism declared as
xmlns:soap="..."and used via prefixed tag names such as<soap:Envelope>. It lets XML from different vocabularies coexist in a single document without name collisions, and it's used heavily in SOAP messages. - CDATA section
- Text wrapped in
<![CDATA[ ... ]]>that the XML parser leaves alone instead of interpreting as markup. Useful for embedding HTML snippets or source code containing angle brackets without escaping every character. - Processing instruction
- A directive wrapped in
<?and?>, such as the XML declaration<?xml version="1.0"?>at the top of a document. Processing instructions embed instructions aimed at the parser or the consuming application. - DTD (Document Type Definition)
- One mechanism for defining which elements and attributes an XML document is allowed to contain. It's declared with
<!DOCTYPE ...>; XML Schema (XSD) is a more capable alternative that's also widely used today.
Frequently asked questions
< and &.<ns:tag>, are matched including the prefix, so this validates and formats correctly even for namespace-heavy XML such as SOAP messages.
Side Note — XML, the offspring of SGML
XML (Extensible Markup Language) became a W3C recommendation in 1998, and its lineage traces back to SGML (Standard Generalized Markup Language), a sprawling document-description standard from the 1980s — XML was designed as a simplified subset of it. HTML is another SGML application, making XML and HTML siblings in the same family.
In the early 2000s, XML spread rapidly as the standard format for web APIs and business-to-business data exchange (EDI), led by SOAP. Its support for attributes, namespaces, and strict typing via XML Schema made it well suited to enterprise use cases of the era.
By the 2010s, JSON had taken over as the dominant format, but XML never disappeared. It remains the standard in domains that need rich structured-document expressiveness: RSS/Atom feeds, SVG images, the internal formats of Office documents (docx/xlsx), and Android layout files, to name a few.
This tool is the third in Toolbase's formatter lineup, following the JSON and SQL formatters — together they round out the three major data formats developers work with day to day.