Skip to content

XML formatter

Paste XML to indent it neatly or make it compact.

0 characters · 0 lines

0 characters · 0 lines

Your files are open only in this tab. Nothing is uploaded.

How to use XML formatter

  1. Paste XML or open a local file. Drop or select .xml, .svg, .xsd, .rss, or .atom files up to 20 MB, or click Try an example.
  2. Choose Format or Minify mode. In Format mode, select 2 spaces, 4 spaces, or Tabs under Indent.
  3. Fix any structural syntax errors. If a tag is unclosed or mismatched, click Go to line to jump straight to the highlighted line and column.
  4. Copy or download the output. Click Copy for the clipboard or Download to save formatted.xml locally.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

How does the XML well-formed check catch tag errors by line?

The validator tokenizes your document into opening, closing, self-closing, comment, CDATA, and text nodes, then walks a tag stack to verify structural well-formedness. Any mismatch throws a ParseError with the exact 1-based line and column number.

Well-formedness violation Error reported by parser Typical cause
Missing closing tag <book> is never closed Deleted or truncated </book> at file end
Wrong nesting order Expected </title> but found </book> Overlapping tags such as <a><b></a></b>
Extra closing tag </item> closes a tag that was never opened Duplicate closing tag after refactor
Multiple top-level tags XML must have exactly one root element Concatenated log snippets without a wrapper
Unescaped < in text A "<" that doesn't start a tag (write &lt; instead) Math comparison x < 5 outside CDATA

Detecting unclosed, mismatched, and multi-root elements

Under the W3C Extensible Markup Language (XML) 1.0 Specification, an XML processor must reject documents that violate nesting or single-root rules. This XML beautifier checks every opening tag against the stack and rejects stray non-whitespace text outside the root element.

When debugging multi-format API integrations where services exchange both XML and JSON, you can inspect the XML structure here and format and validate JSON API responses in the companion tool.

Jumping to exact line and column errors with Go to line

Large configuration files and SAML assertions often span thousands of lines, making manual tag counting tedious. When checkXml() detects an error, the editor displays the human-readable message alongside a Go to line button.

Clicking Go to line focuses the input textarea, scrolls the offending line into view, and selects from the exact column to the end of the line. You can fix the missing slash or unescaped &lt; immediately and watch the Formatted panel update live.

XML indentation options, mixed inline content, and xml:space

Switching Mode to Format indents nested elements cleanly while respecting inline text boundaries and whitespace-preservation attributes. Unlike naive line-by-line regex formatters, the block analyzer inspects child nodes before adding newlines.

Tip: Open .svg vector files directly via Open file to inspect messy Illustrator or Figma exports with clean 2-space indentation before editing paths by hand.

Choosing 2 spaces, 4 spaces, or Tabs in Format mode

Use the Indent dropdown to switch between 2 spaces, 4 spaces, and Tabs. The formatter also normalizes extra whitespace between attributes inside tags while leaving quoted attribute values ("..." and '...') untouched.

For .svg assets that are already valid and need aggressive size reduction for web delivery, you can minify SVG markup and strip redundant editor metadata instead of only re-indenting tags. Both tools share the same W3C Scalable Vector Graphics (SVG) 2 Specification XML foundation.

Preserving mixed inline elements and CDATA blocks

Many pretty-printers corrupt documentation and XHTML-style XML by putting <p>, <b>, and </b> on separate lines, which introduces unwanted spaces in rendered text. Here, analyzeXmlBlocks() detects mixed text-and-element children and keeps the entire inline block on a single indented line.

Elements carrying xml:space="preserve" and leaf <![CDATA[...]]> blocks are also kept intact without injecting internal line breaks. Only multi-line pure-text blocks or nested container elements expand across lines.

Why XML vs HTML parsing rules differ, and when to minify XML markup

HTML5 browsers silently auto-close missing tags and reorder broken nesting, whereas XML parsers fail immediately on the first syntax error. Understanding that strictness explains why an HTML snippet often fails XML validation until self-closing tags and entities are fixed.

Strict XML fatal errors vs forgiving HTML5 recovery

As documented in the MDN DOMParser Web API Reference, parsing with text/html applies error-recovery rules, while application/xml or text/xml halts on a <parsererror>. Unclosed <br> or <img> tags, unquoted attributes, and bare & characters are valid in HTML5 but fatal in XML.

When your goal is turning rendered HTML markup into a printable document rather than strict XML serialization, switch to HTML to PDF document rendering instead of forcing HTML through an XML validator.

Stripping comments and whitespace safely in Minify mode

Selecting Minify removes <!-- ... --> comments, collapses redundant attribute spacing, and trims inter-element newlines to shrink payload size. Any element marked with xml:space="preserve" retains its exact internal whitespace and tag formatting, protecting preformatted code snippets or address blocks from accidental collapse.

Minifying is ideal before embedding XML in test fixtures, SOAP requests, or database columns where extra indentation wastes bytes. Switching back to Format restores readable indentation on the minified output whenever you need to audit the tree structure again.

Inspecting SOAP envelopes, SAML assertions, RSS feeds, and XSD files locally

Formatting XML in the browser avoids uploading authentication tokens, partner schemas, or proprietary feeds to third-party servers. Everything runs in local memory with zero network calls, and automatic worker offloading keeps large documents responsive.

  • Accepted file formats: Click Open file or drag and drop .xml, .svg, .xsd, .rss, or .atom files up to 20 MB directly into the input pane, then download the result as formatted.xml.
  • Responsive large-file handling: Inputs larger than 65,536 characters (64 KB) automatically run inside a dedicated Web Worker with a 120 ms debounce so the UI stays responsive.
  • Debugging SOAP and SAML: Paste base64-decoded SAML assertions or SOAP envelopes to trace namespace prefixes and nested signatures without exposing identity tokens to external servers.
  • Exporting tabular XML data: When an XML feed contains repeating records you need to analyze in a spreadsheet, convert repeating XML records into spreadsheet tables after checking well-formedness here.

Questions

Does the XML formatter validate against an XSD schema?

No. It verifies structural well-formedness, meaning every tag is properly closed, nested, and wrapped in a single root element, rather than validating element types or cardinality against an XSD or DTD.

How does the tool handle mixed inline content inside text elements?

When an element mixes text and child tags, such as a paragraph containing bold or link tags, the analyzer keeps that element on one line instead of injecting line breaks that would alter rendered word spacing.

Are XML declarations, namespaces, and CDATA sections preserved?

Yes. Processing instructions such as XML version declarations, DOCTYPE definitions, xmlns namespace attributes, and raw CDATA character blocks remain intact in both Format and Minify modes without altering their internal contents.

Does the formatter support non-English UTF-8 tag names?

Yes. The tokenizer uses Unicode letter and digit character classes, so localized element and attribute names with accented characters or non-Latin scripts parse without false errors.

Why are comments and extra spaces removed during minification?

Minify mode strips XML comment blocks and collapses whitespace between tags to reduce wire size for SOAP payloads and RSS feeds, while leaving text inside xml:space="preserve" untouched.

Are confidential SOAP envelopes or SAML assertions uploaded anywhere?

No. All tokenizing, well-formedness checks, and indentation run inside your browser tab or local Web Worker, so authentication assertions and internal payloads never leave your device.

Updated