About the XML Formatter
XML is strict: a single unclosed tag or stray ampersand makes a whole file unusable to the software that reads it. This XML formatter indents a document so its structure is easy to follow and validates it with your browser's XML parser, reporting the line and problem when it will not parse. Namespaces, CDATA sections, comments and processing instructions are handled correctly, so sitemaps, feeds, invoices and configuration files come out readable and intact. Validation happens before formatting, so you never get a neatly indented but broken file. To convert XML for modern code, use the XML to JSON Converter, and for JSON documents, the JSON Formatter.
Checking is done by the XML parser that ships with your browser, the same engine that reads feeds and SVG files, so the verdict is genuine rather than a rough imitation. When a document is rejected you see that parser's own explanation, with the line where it gave up and what it found there, which is usually enough to fix the problem in seconds.
The parts of XML that confuse simpler tools are handled with care. Prefixes such as xsi: or g: stay attached to their elements, CDATA sections are copied byte for byte, comments and processing instructions remain where they were, and attribute values are never touched. A minify mode does the opposite job, squeezing a document back onto a single line when it needs to be compact. A short summary also reports how many elements the document contains and how deeply they nest.
How to use the XML Formatter
- Paste the documentAn RSS feed, a sitemap, a configuration file, an API response or any other XML.
- Choose the indentationTwo spaces, four spaces or a tab.
- Run FormatA valid document is indented neatly; an invalid one produces an error that names the line.
- Take the outputCopy it or download the formatted file.
XML Formatter features
- Validation by the XML parser built into your browser
- Error messages that give the line and the cause
- Namespaces, CDATA, comments and processing instructions kept intact
- Indentation of your choice
- Minify mode that puts the document back on one line
- Counts of elements and nesting depth
- Copy or download the result
Common uses
- Reading a podcast or news feed in RSS or Atom format
- Checking a sitemap for errors before submitting it
- Tidying an application or build configuration file
- Finding the tag that was never closed in a broken file
- Looking through the XML returned by a web service
Formatting XML in practice: a sitemap Search Console rejects, broken RSS feeds, blank lines before the declaration, invisible characters and Office files
When an XML file fails, everything that reads it fails with it: search engines ignore a broken sitemap, feed readers stop updating and integrations reject requests. Formatting and parsing the file is the quickest way to find out why. This guide fixes a sitemap with an unescaped ampersand, then covers broken feeds, the blank-line error common on WordPress sites, invisible control characters, encoding mismatches, sitemap limits and the XML hidden inside Office documents.
A worked example: a sitemap with an ampersand
Search Console reports that a sitemap could not be read. Pasting it into the formatter produces a parsing error on a line containing a URL such as /products?colour=red&size=large. In XML, a bare ampersand starts an entity reference, so it must be written as &. Escaping the ampersands in that URL, and fixing the sitemap generator so it escapes them automatically, makes the file parse and lets Search Console process it again.
Broken RSS feeds
Feed readers and podcast directories reject feeds with invalid XML, often silently. Common causes are unescaped ampersands in titles, HTML pasted into descriptions without CDATA or escaping, and characters copied from word processors. Formatting the feed and reading the parser's error message points to the exact item that needs fixing.
Blank lines before the declaration
The XML declaration, the line beginning with <?xml, must be the very first thing in the file. On WordPress sites, a blank line or space printed by a theme or plugin file, often after a closing PHP tag, pushes the declaration down and breaks feeds and sitemaps with an error about the declaration not being at the start. Finding and removing the stray whitespace in the offending file fixes every feed at once.
Invisible characters
XML 1.0 forbids most control characters, such as vertical tabs and other characters below code 32 except tab, line feed and carriage return. They sneak in through text copied from documents and old databases and are invisible on screen. When the parser reports an invalid character on a line that looks fine, removing and retyping the text on that line usually clears it.
Encoding mismatches
If a file declares one encoding, such as ISO-8859-1, but is actually saved as UTF-8, Urdu and other non-Latin text appears garbled or fails to parse. Declaring UTF-8 and saving the file as UTF-8, which is the default for XML when no encoding is declared, avoids the mismatch.
Sitemap limits
A single sitemap may list up to 50,000 URLs and must not exceed 50 MB uncompressed. Larger sites split their URLs across several sitemaps and list those in a sitemap index file. Formatting a sitemap and counting its url entries shows whether a site is close to the limit.
XML inside Office files
Word and Excel files in the .docx and .xlsx formats are ZIP archives full of XML files. Renaming a copy to .zip, extracting it and formatting a file such as word/document.xml shows the document's internal structure. This helps when diagnosing corrupted documents or extracting text that other tools cannot read.
Formatting and whitespace
Indenting data-oriented XML, such as sitemaps, feeds and configuration files, is harmless. In document-style XML, where text and elements mix, added whitespace can become part of the text. Keep the original file when formatting such documents, and use the formatted copy for reading and diagnosis.
Common mistakes
- Leaving bare ampersands in URLs and titles.
- Printing whitespace before the XML declaration.
- Declaring an encoding different from the file's actual encoding.
- Exceeding sitemap limits without a sitemap index.
Related tools
To build a valid sitemap, use XML Sitemap Generator. To convert XML for code, try XML to JSON Converter, and to escape special characters, HTML Encoder & Decoder.
Namespaces in sitemaps
Sitemaps that include images, videos or alternate language versions use extra namespaces, declared on the urlset element, such as xmlns:image for image entries. Using a prefix such as image: without declaring it produces a parse error about an unbound prefix. Checking the declarations at the top of the file fixes this common mistake.
Compressed sitemaps
Sitemaps may be served compressed, for example as sitemap.xml.gz, which saves bandwidth for large sites. The size limit applies to the uncompressed file. To inspect a compressed sitemap, decompress it first and then format the XML, since the compressed bytes cannot be read directly.
Configuration files
Android manifests, Maven project files and .NET configuration files are all XML, and a misplaced closing tag can stop a build or an application from starting. Formatting the file shows mismatched nesting at a glance, because an element that closes in the wrong place breaks the indentation pattern below it.
Comparing versions
When a feed or configuration file suddenly stops working, format both the last working version and the current one, then compare them line by line. Formatting first means the comparison shows real differences, such as a removed element or a changed attribute, rather than differences in line breaks and indentation.
Privacy
Parsing and formatting use your browser's XML parser. Your documents are not uploaded or stored.
Frequently asked questions
Why will my XML not parse?
The usual suspects are a tag that is never closed, a bare ampersand that should be written &, an opening and closing tag that differ in capitalisation, or two top-level elements. XML allows exactly one root and is case-sensitive, which often surprises people used to HTML.
How is XML different from HTML?
XML has no tolerance for mistakes: every element must be closed, every attribute value needs quotes, and the whole document sits inside one root element. Browsers forgive all three in HTML, which is why markup that looks fine on a web page can fail as XML.
Does the formatter touch CDATA sections?
No. A CDATA section exists to hold text that must not be parsed, such as code or HTML fragments, so it is copied exactly. Indenting inside it would change the data stored there.
Can it check my document against a schema?
No. It confirms that the document is well-formed, meaning the structure is legal XML. Checking it against a DTD or an XSD schema is a separate step that requires the schema file itself.
How big a file can I format?
Documents of a few megabytes are handled comfortably. Much larger files can become slow, because the whole document is loaded into memory in your browser tab before it is checked and indented.
Is my XML uploaded anywhere?
No. Parsing and formatting both happen in your browser, so configuration files with passwords, invoices and internal data feeds stay on your own computer and are never stored by anyone else.