XML Formatter and Validator
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free XML formatter. Pretty-print XML with clean indentation, minify it, and check that it's well-formed, with the line of any error. Runs in your browser.
- Well-formed
- 0
- Elements
- 0
- Before
- 0
- After
- 0
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the XML formatter
- Paste your XML into the box: a sitemap, an RSS feed, a SOAP response, a config file, a product feed or an export from another system.
- Choose what to do. Format (beautify) lays it out with one element per line and clean indentation; Minify removes the whitespace between tags to make it as small as possible.
- Pick the indent: 2 spaces, 4 spaces or a tab.
- Read the check. The XML formatter tells you whether the XML is well-formed, counts the elements, and shows the size before and after.
- Copy the result.
Everything runs in your browser, so you can paste internal API responses and private data feeds without them being sent anywhere.
Validation: is your XML well-formed?
Before formatting, the tool passes your XML to the browser's own XML parser, the same one browsers use to read RSS feeds and SVG files. If the parser rejects it, you see "Not well-formed" with the parser's message, usually including the line and column of the first problem.
Well-formed XML follows a few strict rules:
- There's exactly one root element that contains everything else.
- Every opening tag has a closing tag (
<name>…</name>), or closes itself (<br/>). - Tags nest properly.
<a><b></b></a>is fine;<a><b></a></b>isn't. - Tag names are case-sensitive.
<Item>and</item>don't match. - Attribute values are in quotes, single or double, and an attribute appears only once per element.
- Special characters are escaped in text and attributes:
&must be written&and<must be<.
The most common errors in practice are an unescaped & in a URL or a company name ("Bread & Butter"), a missing closing tag, and stray text before the XML declaration. If the formatted output looks odd, fix the reported error first: formatting broken XML can't fix it.
Well-formed isn't the same as valid against a schema. An XML document can be perfectly well-formed but still use the wrong element names for, say, a sitemap. This XML formatter checks the syntax; a schema validator checks the vocabulary.
Formatting: what changes and what doesn't
When you format XML, the tool:
- Puts each element on its own line, indented to show how deep it is.
- Keeps short elements on one line when they only contain text, such as
<name>Sourdough</name>, so the result stays readable. - Keeps the XML declaration, comments, CDATA sections and processing instructions.
- Removes the whitespace between tags and replaces it with consistent indentation.
What it doesn't change:
- Text content. The words inside elements are kept as written, apart from trimming spaces at the start and end of text that sits between tags.
- Attributes. They stay in the same order with the same values and quotes.
- Element names and namespaces. Prefixes like
xs:org:are left alone.
One caution: in a few XML formats, whitespace inside mixed content is meaningful, for example in some document formats where text and tags mix inside a paragraph. If you're formatting that kind of file, compare the result before using it as data. For data formats such as feeds, sitemaps, configs and API responses, formatting is safe.
Minifying XML
Minify removes all the whitespace between tags. It's useful for:
- API payloads, to reduce the size of each request and response.
- Embedding XML in another file or a database field.
- Feeds and sitemaps served very often, where every byte adds up.
Tick "Remove comments when minifying" to drop <!-- … --> comments too. Text inside elements is kept, and so are CDATA sections. The tool shows how much smaller the result is. Remember that servers usually compress XML with gzip or Brotli anyway, so minifying matters most where compression isn't available.
Common XML you might format
XML sitemaps. Search engines read sitemap.xml to find a site's pages. Formatting makes it easy to check that every <url> has a <loc> and the right <lastmod>. If you need to build one, the XML sitemap generator makes it for you.
RSS and Atom feeds. Blog and podcast feeds are XML. Formatting shows the channel, the items and their links clearly, which helps when a feed reader or podcast platform rejects your feed.
Product feeds. Google Merchant Center and other shopping platforms accept XML feeds with one <item> per product. Formatting helps you spot missing prices, broken links and wrong availability values.
SOAP and older APIs. Many banking, shipping and government systems still use XML. Responses usually arrive as one long line; formatting makes them readable.
Config files. Android layouts and manifests, Maven pom.xml files, .NET config files and many more are XML.
Office files. Word, Excel and PowerPoint files are ZIP archives full of XML. If you unzip one, the XML formatter makes the parts readable.
XML or JSON?
XML and JSON both describe structured data. JSON is shorter and is now the default for most web APIs; XML supports attributes, namespaces, comments and mixed text, and remains common in documents, feeds, enterprise systems and configuration. If you work with both, the JSON formatter does the same job for JSON, and the CSV to JSON converter turns spreadsheet data into JSON.
Tips for working with XML
Escape ampersands. Any & that isn't the start of an entity, such as & or ©, breaks the document. Search for " & " in your text before publishing a feed.
Use CDATA for blocks of HTML. If an element contains HTML, such as a product description, wrap it in <![CDATA[ … ]]> so the angle brackets aren't read as XML tags.
Declare the encoding. Start files with <?xml version="1.0" encoding="UTF-8"?> and save them as UTF-8, so accented letters and symbols survive.
Check after editing by hand. A quick paste into the XML formatter catches a missing closing tag before it breaks a feed or a build.
Search large files with regex. To find every element with a certain attribute, the regex tester helps you build and test a pattern.
Your data stays private
The XML formatter parses and formats in your browser. Nothing you paste is uploaded, logged or stored, so it's safe for API responses with customer data, internal configuration files and unreleased product feeds.
A worked example
A bakery's developer is debugging the online shop's product feed. The shopping platform says the feed has an error but doesn't say where, and the feed is one 40 KB line of XML.
She pastes it into the XML formatter. The result says "Not well-formed" and the parser message points to line 1, column 18,342: an entity problem. She searches near that point and finds <title>Bread & Butter Pudding</title>: an unescaped ampersand. She changes it to Bread & Butter Pudding in the shop's product settings and fetches the feed again.
This time it's well-formed, with 1,284 elements. She formats it with 2-space indentation and scrolls through: every <item> now clearly shows its <g:price> and <g:availability>. She spots two products with no price and fixes those too. The platform accepts the feed that afternoon.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit is a Google Ads agency that does PPC and nothing else: we build the campaigns, block the searches that waste money, write the ads, set up conversion tracking and send you a short report every week. Request a free PPC audit and we will show you, in dollars, what we would fix first.
Frequently asked questions
How do I format XML online?
Paste the XML into this XML formatter, choose Format and an indent size, and copy the result. It's free and runs in your browser.
How do I check whether XML is valid?
The tool checks that the XML is well-formed using the browser's XML parser and shows the first error with its line and column. Checking against a schema (XSD) is a separate step that needs the schema file.
Does formatting change my data?
No. Element names, attributes and text are kept as they are. Only the whitespace between tags changes. In rare document formats where spaces in mixed text matter, compare the result before using it.
What does minify XML do?
It removes the whitespace between tags, and optionally comments, to make the file as small as possible without changing the data.
Is my XML uploaded?
No. The XML formatter works entirely in your browser; nothing is sent to a server.
Why does my XML say it isn't well-formed?
The most common causes are an unescaped & character, a missing or mismatched closing tag, or text before the XML declaration. The error message shows where the parser stopped.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.