XML Formatter

XML Formatter

Paste XML to indent it, minify it or check that it is well-formed. If something is wrong, you see the line and column of the first error, the spot marked in your text and how to fix it. Text content is never touched, and your XML never leaves the browser.

Output
Indent
  • Formatted XML

    <?xml version="1.0" encoding="UTF-8"?> <catalog xmlns:dc="http://purl.org/dc/elements/1.1/"> <!-- two books --> <book id="bk101" lang="en"> <dc:title>XML Developer&apos;s Guide</dc:title> <price currency="USD">44.95</price> <note>Ships in <b>2 days</b>.</note> </book> <book id="bk102" lang="en"> <dc:title>Midnight Rain</dc:title> <price currency="EUR">5.95</price> <summary><![CDATA[An architect battles <corporate> zombies & wins.]]></summary> </book> </catalog>

ResultWell-formed XML
Elements10
Nesting depth4
Attributes7
Namespace declarations1
Size before (bytes)452
Size after (bytes)499
Change in size10.4%
Lines14

Only whitespace between tags changed — text, attribute values, CDATA and comments are copied exactly as written.

Calculated on your device · formulas checked against known results · How we test

How to use the XML formatter

  1. Paste your XML into the box — an NF-e or other electronic invoice, a SOAP request or response, an RSS feed, a sitemap, a Maven pom.xml, an Android layout or an SVG file. It is checked and formatted as you paste.
  2. Choose Format to put every element on its own line, indented with 2 spaces, 4 spaces or a tab, or Minify to remove the whitespace between tags.
  3. Press Copy beside the result, or Download to save it as a file.
  4. If the XML isn’t well-formed, you get the problem, its line and column, the line itself with a ^ under the spot and how to fix it. Fix it and the formatted XML appears straight away.

What the formatter changes — and what it never touches

An XML document is a tree of elements. Formatting puts each child element, comment and processing instruction on a line of its own, indented by how deeply it is nested; minifying removes those line breaks and indents again. Only elements whose content is made of other elements get this treatment, because only there is the whitespace between tags insignificant. Everything else is copied character for character:

Windows line breaks (CR LF) are written as LF, as every XML parser reads them anyway.

What “well-formed” means

Every XML file must follow the syntax rules of XML 1.0 and Namespaces in XML, or no program will read it. The checker reports the first broken rule it finds: one root element that contains everything; every start tag closed by a matching end tag, in the right order and with the same case; attribute values in quotes and no attribute twice in one tag; & and < in text escaped as &amp; and &lt;; only the five predefined entities unless a DOCTYPE declares more; every namespace prefix such as dc: declared with xmlns:dc="…"; the <?xml … ?> declaration, if present, as the very first characters of the file. For example:

  <client>Smith & Co</client>
                ^

This shows Unescaped & at line 2, column 17: the ampersand in a company name must be written Smith &amp; Co. It is the most common error in invoices and product feeds built by hand.

Well-formed is not the same as valid. Validation checks a document against a schema (XSD or DTD) that says which elements and values are allowed — for an NF-e, the schemas published with the Brazilian tax authority’s technical notes. This page checks the syntax, not a schema.

Worked example

The sample in the box is a 452-byte catalog on a single line, with a namespace, a comment, mixed content and a CDATA section. Formatted with 2 spaces it becomes:

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:dc="http://purl.org/dc/elements/1.1/">
  <!-- two books -->
  <book id="bk101" lang="en">
    <dc:title>XML Developer&apos;s Guide</dc:title>
    <price currency="USD">44.95</price>
    <note>Ships in <b>2 days</b>.</note>
  </book>
  <book id="bk102" lang="en">
    <dc:title>Midnight Rain</dc:title>
    <price currency="EUR">5.95</price>
    <summary><![CDATA[An architect battles <corporate> zombies & wins.]]></summary>
  </book>
</catalog>

The 10 elements are nested 4 levels deep. The <note> element mixes text and a tag, so it stays on one line, and the CDATA section keeps its <corporate> and its bare &. Indenting adds 47 bytes; minifying the formatted version brings it back to 452 bytes.

Signed XML: NF-e, CT-e, SAML, SOAP

Electronic invoices and many web-service messages carry an XML digital signature. The signature covers the exact text of the signed elements, including the whitespace between tags, so a formatted copy of a signed NF-e no longer matches its signature and the tax authority’s web service rejects it. Format a signed file to read it or to find an error, but send and archive the original. Minifying is just as unsafe if the original was signed with line breaks in it.

Limits and tips

Your XML stays on your device

Parsing, checking and formatting all run in your browser. Invoices and API messages often contain tax IDs, addresses and prices; none of it is uploaded or logged, and it isn’t saved either: reloading the page clears it.

Frequently asked questions

Is my XML uploaded to a server?

No. The formatter is JavaScript that runs in your browser, so your file never leaves your device, and the page keeps working offline once it has loaded.

What is the difference between well-formed and valid XML?

Well-formed XML follows the syntax rules every XML parser enforces: tags closed and nested properly, attribute values quoted, special characters escaped, one root element. Valid XML is well-formed and also matches a schema (XSD or DTD) that defines which elements and values are allowed. This page checks well-formedness.

Why do I get “Unescaped &”?

In XML an ampersand starts a reference such as &amp; or &#233;. A plain & — in a company name, a product description or a URL with several parameters — must be written &amp;.

Can I format an NF-e and still send it?

No. The digital signature covers the exact text of the invoice, whitespace included, so a formatted copy fails the signature check. Use the formatted version to read the invoice, and keep and send the original file.

Why does the formatter leave some elements on one line?

An element that contains text — alone or mixed with tags — is copied exactly as written, because adding line breaks or spaces inside it would change the text. Only elements that contain nothing but other elements, comments and processing instructions are spread over several lines.

Embed this calculator on your website

Free for any website or blog. Paste this code where you want the calculator to appear:

All free calculator widgets

Last updated: October 16, 2026

Menu

Categories

Finance Calculators30 calculatorsBusiness & Shopping Calculators9 calculatorsHealth & Fitness Calculators13 calculatorsMath & School Calculators23 calculatorsDate & Time Calculators19 calculatorsHoliday Countdowns17 calculatorsEveryday Tools47 calculatorsMic, Camera & Sound Tools10 calculatorsDeveloper Tools10 calculatorsImage & PDF Tools19 calculators

CalcWorthy

AboutContactPrivacy PolicyTerms of Use

Language

Language
EnglishEnglishالعربيةArabicবাংলাBanglaDeutschGermanEspañolSpanishفارسیPersianFrançaisFrenchעבריתHebrewहिन्दीHindiBahasa IndonesiaIndonesianItalianoItalian日本語Japanese한국어KoreanBahasa MelayuMalayNederlandsDutchPolskiPolishPortuguêsPortugueseРусскийRussianไทยThaiTürkçeTurkishУкраїнськаUkrainianاردوUrduTiếng ViệtVietnamese简体中文Simplified Chinese