Skip to content
SocialTools

XML Formatter

Paste XML to confirm it parses, then read it with one tag per line and two-space nesting.

What it does

The formatter first parses your input with the browser's DOMParser as application/xml. If the document is not well-formed (an unclosed tag, a stray ampersand, mismatched names) you get an "Invalid XML" message. If it parses, the tool puts each tag on its own line and indents child elements by two spaces.

Typical inputs are XML sitemaps, RSS and Atom feeds, SOAP responses, Android or Maven config files, and product feeds for shopping platforms, which often arrive as a single unbroken line. The check and formatting rerun on every edit, so you can fix an error and see the result straight away.

How to use it

  1. 1

    Paste your XML into the XML input box.

  2. 2

    If a red Invalid XML message appears, fix the document and it re-checks as you type.

  3. 3

    Read the indented result in the Formatted box.

  4. 4

    Click Copy above the Formatted box.

What you get

The document with whitespace between tags removed and each tag placed on its own line, nested elements indented two spaces per level. Invalid input shows "Invalid XML" and an empty Formatted box.

When to use it

Check a sitemap before submitting
Paste your sitemap.xml to confirm it is well-formed; a parse error can stop search engines from reading it.
Read one-line feed files
Break an RSS feed or product feed onto separate lines so you can scan items and attributes.
Catch unescaped ampersands
A raw & in a URL or title is a common reason feeds fail; the Invalid XML message flags it before a platform does.

Example

Input

<feed><entry id="1"/><entry id="2"/></feed>

Output

<feed>
  <entry id="1"/>
  <entry id="2"/>
</feed>

Self-closing tags and the XML declaration do not add an indent level.

Tips

  • The indenter works tag by tag and is built for element structure. For elements that hold text, like <loc>https://example.com/</loc>, the closing tag is moved to its own line and indentation after it can drift. Use the output for reading, and keep your original file as the source of truth.
  • The check confirms well-formedness only. It does not validate against a schema or DTD, so a sitemap with a misspelled element name can still pass.
  • Escape & as &amp; inside URLs and text. The HTML Encoder handles this if you paste the raw value.
  • Whitespace between tags is removed before formatting, so the output is not suitable where that whitespace is meaningful, such as mixed-content documents.

Questions

What makes XML invalid in this checker?

Anything that stops the browser's XML parser: tags that are not closed or not nested properly, attribute values without quotes, more than one root element, or a bare & that is not part of an entity.

Does it validate my sitemap against the sitemap protocol?

No. It checks that the file is well-formed XML. Whether it uses the right elements, like urlset, url and loc, has to be checked against the sitemap protocol separately.

Why does a text value end up on a different line from its closing tag?

The formatter splits at every < character, so the text stays with its opening tag and the closing tag starts a new line. The XML is unchanged in meaning; it is a display quirk of the tag-by-tag indenter.

Can I convert this XML to JSON?

Not here. The tool only checks and indents XML. If your data is tabular, exporting it as CSV and using the CSV to JSON converter is often simpler.