Developer

XML Formatter

Format and indent XML with well-formedness checking, and understand where whitespace in XML is significant.

Last reviewed by the Radiatus Cloud team

XML Formatter

Beautify and format XML data for better readability.

Need this built for your product?

We design, build & host secure software & APIs.

Talk to an engineer

Well-formed and valid are different

Well-formed means the syntax is correct: one root element, every tag closed, attributes quoted, entities escaped. Valid means the document also conforms to a schema or DTD. A formatter checks well-formedness, because it must parse the document to indent it. It cannot tell you whether the structure is the one your system expects; that needs a schema.

Indenting can change the document

This is the trap that makes XML formatting riskier than JSON formatting. Whitespace between elements is usually insignificant, but whitespace inside an element containing text is part of the content. Reformatting a document with mixed content, where text and elements interleave, alters the text. An element declared with xml:space set to preserve must be left exactly as it is. A formatter that indents everything uniformly corrupts those cases silently.

Five entities and no more

XML predefines only ampersand, less-than, greater-than, apostrophe and quote. Everything else must be a numeric character reference or declared in a DTD. This catches people arriving from HTML, where a non-breaking space entity is standard: that entity is undefined in plain XML and makes the document not well-formed.

The declaration and encoding

The XML declaration states the version and encoding. If the declared encoding does not match the actual bytes, parsing fails or produces mojibake, and a byte order mark on a document declared as UTF-8 without one is a common cause. UTF-8 is the sensible default and needs no BOM.

Namespaces are why elements have colons

A prefixed element name binds to a namespace URI declared with an xmlns attribute. The prefix itself is arbitrary; the URI is what identifies the namespace, so two documents using different prefixes for the same URI are equivalent. A formatter must preserve declarations exactly, because moving or dropping one changes which namespace an element belongs to.

Never parse XML from untrusted sources naively

External entity expansion allows a document to read local files or make network requests, which is the XXE vulnerability class. Billion-laughs entity expansion can exhaust memory. Any parser handling untrusted XML should disable external entities and limit expansion. This tool parses in your browser, where those features are unavailable by default.

Related tools

  • JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
  • JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
  • Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
  • HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.

Frequently Asked Questions

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

Well-formed means the syntax is correct. Valid means it also conforms to a schema or DTD. A formatter checks the first because it must parse to indent, but it cannot tell you the structure is what your system expects.

Can formatting change my XML?

Yes, in specific cases. Whitespace inside an element containing text is content, so reformatting mixed content alters it, and elements with xml:space set to preserve must be left untouched.

Why is my non-breaking space entity invalid?

XML predefines only five entities: ampersand, less-than, greater-than, apostrophe and quote. HTML's named entities are undefined in plain XML and make the document not well-formed. Use a numeric reference.

Why does my XML fail to parse with strange characters?

Usually the declared encoding does not match the actual bytes, often a byte order mark on a document declared UTF-8 without one. UTF-8 is the sensible default and needs no BOM.

Is parsing untrusted XML dangerous?

It can be. External entity expansion lets a document read local files or make requests, the XXE class, and nested entities can exhaust memory. Disable external entities on any parser handling untrusted input.

Privacy & Security

Local processing.

Data: None
Client-side-Side
Active
v1.0

About This Tool

This tool runs entirely in your browser. No data is sent to any server, ensuring complete privacy. Simply use the interface above to get started — no registration or login required.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.