Developer

XML Formatter

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

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.

Frequently Asked Questions

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.