Home › Developer Tools › XML Formatter

XML Formatter

Paste XML or open a file to beautify, minify or validate it. Errors are reported with the line and column, comments and CDATA are kept, and text content is never changed.

Last updated:

Input
Waiting for XML…

      
      

Everything runs in your browser. Files you open are read locally and never uploaded.

Advertisement
Advertisement

How to use the XML Formatter

  1. Paste your XML into the input box, open an .xml file, or press Sample.
  2. Press Format XML and choose 2 spaces, 4 spaces or tabs. The output updates as you type.
  3. Check the status bar. A green tick means the XML is well-formed. Otherwise you get the error message with its line and column; press Go to error to jump there.
  4. Press Minify to remove indentation and line breaks between tags, optionally removing comments.
  5. Switch to Tree to fold elements and click any node to see its path, then copy or download the result.

How the formatter keeps your data intact

Many online beautifiers re-flow every text node, which silently changes data. This XML formatter follows four rules so the output means exactly the same as the input:

  • Only whitespace between tags is changed. Gaps made purely of spaces and line breaks between elements are replaced by consistent indentation.
  • Text stays inline. An element that contains only text, such as <price>44.95</price>, is printed on one line with its text untouched.
  • Mixed content is left alone. In <p>An <b>in-depth</b> look</p> the spaces around <b> are part of the text, so the whole element is kept on one line exactly as written.
  • xml:space="preserve" is respected, and comments, CDATA sections, processing instructions and the DOCTYPE are copied verbatim.

Before and after

Input:

<order id="7"><item sku="A1"><name>Lamp</name><qty>2</qty></item><!-- gift --></order>

Formatted with 2 spaces:

<order id="7">
  <item sku="A1">
    <name>Lamp</name>
    <qty>2</qty>
  </item>
  <!-- gift -->
</order>

Common XML errors and how to fix them

Error messageTypical causeFix
Opening and ending tag mismatchTags closed in the wrong order, or a typo in a closing tagClose the innermost element first: <a><b></b></a>
Extra content at the end of the documentMore than one root elementWrap everything in a single root element
Entity 'nbsp' not definedHTML entities used in XMLUse &#160; or declare the entity in a DTD
xmlParseEntityRef: no nameA bare & in text or an attributeWrite &amp; or wrap the text in CDATA
AttValue: " or ' expectedAttribute value without quotesQuote every value: id="5"
XML declaration allowed only at the startSpaces, a blank line or a second <?xml ?> before the declarationMake <?xml ... ?> the very first characters of the file

Frequently asked questions

What does an XML formatter do?

It re-indents XML so that each nested element starts on its own line with consistent indentation, making the structure easy to read. It only changes whitespace between tags; element names, attributes, text, comments and CDATA sections stay the same.

Does formatting change my data?

No. Whitespace-only gaps between elements are re-indented, but text content is kept exactly as written. Elements with short text, such as <name>Bob</name>, stay on one line, and mixed content (text with inline tags) and elements with xml:space="preserve" are left untouched.

How do I validate XML?

Paste the XML and look at the status bar. The validator uses your browser's XML parser to check that the document is well-formed: one root element, every tag closed and correctly nested, quoted attributes and valid entities. If not, it shows the first error with the line and column.

Does this check my XML against a schema (XSD or DTD)?

No. It checks well-formedness, which is what most parsers require first. Validating against an XSD or DTD needs a schema-aware validator such as xmllint or an IDE.

Why do I get an error about an undefined entity like &nbsp;?

XML only predefines five entities: &amp;, &lt;, &gt;, &quot; and &apos;. HTML entities such as &nbsp; or &copy; are not valid in plain XML unless a DTD declares them. Use a numeric reference instead, for example &#160; for a non-breaking space.

What is the difference between formatting and minifying XML?

Formatting adds line breaks and indentation for people to read. Minifying removes that whitespace between tags to make the file smaller for storage or transfer. Both keep the same data.

Is my XML uploaded to a server?

No. Parsing, formatting and validation all run in your browser, and files you open are read locally.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.XML to JSONConvert XML to JSON with validation.Markdown to HTMLConvert Markdown to clean HTML with a live editor.Regex TesterTest and debug regular expressions live.CSS FormatterBeautify CSS with indent controls and optional property sorting.DMARC Report AnalyzerRead DMARC aggregate XML reports (.xml, .gz, .zip): sources, SPF/DKIM alignment and pass rates.HTML FormatterBeautify and indent HTML code with a live preview.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.ZIP File CreatorCompress files and folders into a ZIP.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.
See all 41 Code Formatters & Validators →