Skip to content
ToolPlankDEV
Developer Tools
100% In-Browser Execution

Updated:

XML Formatter and Validator

Paste XML and this xml formatter indents it as you type, or minifies it to one line. Text inside elements is never changed, comments, CDATA and the DOCTYPE stay, and any error points to its line and column. Nothing is uploaded.

Options:

XML

Input
0 chars · 0 lines

Formatted XML

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

XML summary

Element and attribute counts, depth, namespaces and the size change appear here once the XML is well-formed.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use XML Formatter

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste or open your XML

    Paste XML into the left box, press Paste, or press Upload and pick an .xml, .xsd, .svg, .rss or similar file. Sample loads a one-line product feed. Sitemap, SOAP request, With DOCTYPE and Broken XML load other common cases.

  2. 02

    Pick a mode

    Beautify indents the XML, Minify removes the whitespace between tags, and Validate only checks that the XML is well-formed and reports what it found. The result updates as you type.

  3. 03

    Set the options

    Choose the indent, when attributes go on their own lines, how empty elements are written, whether comments stay and whether attributes are sorted. Open More options to keep, remove or add the XML declaration, pick LF or CRLF line endings, and turn the final newline on or off.

  4. 04

    Fix errors, then copy or download

    If the XML is broken, the message gives the line, the column and a fix. When it is well-formed, the summary shows counts, depth, namespaces and the size change. Press Copy, or Download to save formatted.xml or minified.xml.

What this XML formatter does

An xml formatter takes XML that is hard to read, often a single long line from an API, a build tool or an export, and lays it out with one element per line and an indent for each level. This one also works the other way: Minify strips the layout whitespace so the file is as small as it can be without changing its meaning. A third mode, Validate only, checks the XML and tells you what is in it without writing anything new.

Here is a short RSS feed pasted as one line, and what Beautify gives back with the default 2-space indent:

xml
<rss version="2.0"><channel><title>Shop news</title><item><title>Spring sale</title><description>Up to <b>30%</b> off, ends Friday.</description></item></channel></rss>
xml
<rss version="2.0">
  <channel>
    <title>Shop news</title>
    <item>
      <title>Spring sale</title>
      <description>Up to <b>30%</b> off, ends Friday.</description>
    </item>
  </channel>
</rss>

Notice that the description element stayed on one line with its <b> tag inside. That is on purpose, and the next sections explain why.

What formatting changes and what it never changes

Formatting only touches whitespace that has no meaning: the spaces and line breaks between tags in an element that holds only other elements, and the spacing inside a tag between attributes. Everything else is copied as written.

  • Text inside elements is kept character for character, including leading and trailing spaces.
  • Attribute values and their quote style stay as they are. a='x' is not rewritten as a="x".
  • Entity and character references such as &amp; and &#160; are not expanded or re-encoded.
  • CDATA sections, processing instructions and the DOCTYPE, including its internal subset, are copied exactly.
  • Namespace prefixes and xmlns declarations are never renamed, moved or removed.
  • Element order and attribute order stay the same, unless you turn on Sort attributes.

Two things do change across the whole file. Line endings are written as LF or CRLF, as you choose, which is also what every XML parser does when it reads a file. And the extra spaces inside a tag are tidied, so <server host="db" /> becomes <server host="db"/>.

Whitespace pitfalls in mixed content

Mixed content means an element holds text and child elements side by side, as in <p>Price: <b>9</b> <i>EUR</i></p>. The single space between </b> and <i> is part of the text. A formatter that puts <b> and <i> on their own indented lines adds new spaces and line breaks to that text, so the sentence reads differently and a signed document no longer matches its signature.

This tool uses a simple rule. If an element contains any text that is not only whitespace, or any CDATA section, the element and everything inside it are written on one line exactly as they were. The same applies to an element whose only content is whitespace, such as <a> </a>, and to every element under xml:space="preserve" until an xml:space="default" switches it back. Only elements that hold nothing but other elements, comments and processing instructions get new line breaks.

Each option in plain terms

  • Mode: Beautify, Minify or Validate only. The other options turn off when they do not apply.
  • Indent: 2 spaces, 4 spaces or a tab per level.
  • Attributes: keep every tag on one line, or put each attribute on its own line once a tag has more than 1, 2, 3 or 5 of them.
  • Empty elements: keep them as written, write all of them as <a/>, or write all of them as <a></a>. Both forms mean the same thing to an XML parser.
  • XML declaration: keep the <?xml ...?> line, remove it, or add <?xml version="1.0" encoding="UTF-8"?> when it is missing.
  • Line endings: the same as the input, LF, or CRLF.
  • Sort attributes: orders attributes from A to Z, with xmlns declarations first. Useful before comparing two files.
  • Keep comments: turn off to drop every comment. CDATA and processing instructions are always kept.
  • Final newline: ends beautified output with a line break, which most editors and Git expect.

With Attributes set to Wrap if more than 2, a tag with four attributes is split while a text element next to it stays on one line:

xml
<order>
  <note>  Leave at door  </note>
  <line
    sku="A-1"
    qty="2"
    price="9.50"
    currency="EUR"/>
</order>

Well-formed XML rules and common errors

Well-formed means the XML follows the grammar of the XML 1.0 specification, so any parser can read it. It is a lower bar than valid, which means it also matches a schema or DTD. The checker in this tool is written for this page and does not depend on the browser, so every mode reports the same errors. It stops at the first problem and gives the line, the column and how to fix it. These are the rules people break most often, with the message the tool prints:

  • Every opening tag needs a matching closing tag with the same name and case. <order>...</ordr> gives: Line 3, column 1: The closing tag </ordr> does not match <order> opened at line 1, column 1.
  • A bare ampersand is not text. <total>3 & 4</total> gives: Line 1, column 10: A bare & is not allowed. Write &amp; for an ampersand.
  • An attribute can appear once per element. <item sku="A-1" sku="A-2"> gives: Line 1, column 17: The attribute sku appears twice in <item>.
  • There is exactly one root element. <a/><b/> gives: Line 1, column 5: A second root element <b> was found.
  • Only five entities are built in: &amp; &lt; &gt; &quot; &apos;. &nbsp; comes from HTML, so the tool suggests &#160; instead.
  • Names cannot start with a digit, a hyphen or a period. <1st> gives: Line 1, column 2: Element names cannot start with "1".
  • Attribute values need quotes, comments cannot contain --, the <?xml ...?> declaration must be the very first thing in the file, an entity cannot refer to itself directly or through other entities, and text cannot contain the characters ]]> in a row or control characters.

Spaces or blank lines before the <?xml ...?> declaration are an error in Validate only. Beautify and Minify remove them and say so in the summary. The checker also warns about things that are well-formed but likely to cause trouble later: a DOCTYPE that names a different root element, entities that may come from an external DTD, a byte order mark, or an encoding other than UTF-8 in the declaration.

Minify or beautify for sitemaps, RSS, SOAP and config files

Beautify is for people: reading an API response, reviewing a change in a pull request, or finding the one wrong value in a long config. Minify is for machines: it trims bytes from files that are sent often and rarely read by hand.

  • Sitemaps: search engines read either form. Minify a large sitemap to save bytes, beautify it when you want to check the URLs and dates.
  • RSS and Atom feeds: minify the published feed, beautify a copy to debug it. Descriptions with HTML inside keep their exact text either way.
  • SOAP messages: beautify a request or response from a log to see its structure. If the message carries an XML signature, do not reformat the signed part, because any change to whitespace in signed content can break the signature.
  • Config files such as pom.xml, web.config, .csproj or Android layouts: beautify with the indent your team uses, and leave comments on, since they often explain settings.

Here is the result of minifying an indented feed. Only the whitespace between tags is gone:

xml
<rss version="2.0"><channel><title>Shop news</title></channel></rss>

Namespaces, DOCTYPE and entities

Namespaces let one document mix vocabularies, such as SOAP envelopes around your own elements. The formatter treats a prefixed name like soap:Body as a plain name and leaves every xmlns attribute where it is. The summary lists each declaration it found with its URI. The tool checks XML 1.0 well-formedness, not the separate Namespaces in XML rules, so namespace problems are warnings, never errors: a prefix such as x:item used without a matching xmlns:x declaration in scope still counts as well-formed, and the summary lists the prefix so you can add the declaration. Namespace-aware parsers will reject such a file.

xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <m:Ping xmlns:m="urn:example:ping"/>
  </soap:Body>
</soap:Envelope>

A DOCTYPE is copied as text, internal subset and all. Entities declared there, such as <!ENTITY company "Example Ltd">, make &company; valid in the document, but the tool never expands them and never fetches an external DTD. That is also why a file built to blow up when its entities are expanded, often called a billion laughs file, does no harm here: the references stay as short text.

Limits worth knowing

  • It checks well-formedness, not validity. It does not test the XML against an XSD schema or a DTD.
  • It reports the first error only. Fix it and the next one, if any, appears.
  • Input is limited to 2,000,000 characters and to 100,000 levels of nesting. Beautified output stops at 12,000,000 characters, which very deep files can reach because of the indent. Minify handles them.
  • Entities from an external DTD cannot be checked, so they are reported as warnings rather than errors.
  • The encoding in the declaration is not used to decode anything. The text you paste is already decoded, and Copy and Download give UTF-8.

For other XML jobs, the XML to YAML converter maps elements to YAML keys, YAML to XML goes the other way, the SVG to XML converter turns SVG into an Android vector drawable, and the HTML encoder escapes <, > and & when you need to show XML as text on a web page.

Privacy

The XML is parsed and formatted by code running in your browser. It is not uploaded, and the DOCTYPE never triggers a download of a DTD. The Privacy Policy describes what the site does store.

Frequently Asked Questions

Technical Q&A for XML Formatter

Common questions about edge cases, character encoding, and privacy guarantees.

No. Any element that holds text, CDATA or only whitespace is written on one line exactly as it was, and xml:space="preserve" is respected. The one change is that line endings follow the option you pick.

Paste it and keep the mode on Beautify. Each element that holds other elements gets its own line and an indent of 2 spaces, 4 spaces or a tab.

It checks that the XML is well-formed and gives the line and column of the first error. It does not validate against an XSD schema or a DTD.

It depends on how much indentation the file had. The summary shows the size before and after and the percentage saved for your own file.

XML has only five built-in entities, and &nbsp; is not one of them. Use &#160; for a non-breaking space, or declare the entity in the DOCTYPE.

Yes. Set Attributes to wrap when a tag has more than 1, 2, 3 or 5 attributes. You can also sort attributes from A to Z, with xmlns declarations first.

Both mean exactly the same thing in XML. Pick one style with the Empty elements option, or keep each one as written.

Yes. CDATA, processing instructions and the DOCTYPE with its internal subset are always kept as written. Comments are kept unless you turn off Keep comments.

Yes. Entities are never expanded and external DTDs are never fetched, so files designed to explode on expansion are formatted as plain text.

No. Formatting, minifying and checking all run in your browser, and nothing you paste or open is sent to a server.