How to use the XML formatter
- 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. - 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.
- Press Copy beside the result, or Download to save it as a file.
- 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:
- Text content, including spaces at its start or end:
<name> Ana </name>keeps both pairs of spaces. - Mixed content — text and tags in one element, such as
<note>Ships in <b>2 days</b>.</note>— stays exactly as written, because a line break there would become part of the text. - Elements marked
xml:space="preserve", with everything inside them. - CDATA sections, comments, processing instructions and the DOCTYPE, including an internal subset in
[ ]. - Entity and character references:
&stays&andéisn’t turned into é. - Attribute values, their quotes and their order. Inside a tag, the spacing is tidied: one space before each attribute and none around the
=, so<x id = "1" />becomes<x id="1"/>.
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 & and <; 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 & 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'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
- Big files: a 200 KB invoice with thousands of elements is checked and formatted in well under a second, and a long result scrolls smoothly. Files of tens of megabytes are more comfortable in a desktop editor.
- Encodings: the page works on the characters you paste, and Download saves UTF-8. If the declaration says
encoding="ISO-8859-1"orwindows-1252, change it toUTF-8in the downloaded file, or accented letters will be read wrongly. - DTD entities: when a document has a DOCTYPE, named entities such as
&co;are accepted without checking that the DTD declares them. - HTML isn’t XML. Tags like
<br>without a closing slash are errors here; use the HTML formatter for web pages. For JSON, use the JSON formatter, and to see what changed between two versions of a file, format both the same way and compare them in the diff checker.
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 & or é. A plain & — in a company name, a product description or a URL with several parameters — must be written &.
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.
Last updated: October 16, 2026