← All tools
// Developer / Data

XML Formatter online

Format and prettify XML with proper indentation — also minifies

XML Formatter / Beautifier logo
by
CHUNKY
MUNSTER
// XML input

How to Use xml-formatter

  1. Paste XML into the input area.
  2. Click Format to indent elements with configurable depth (2 or 4 spaces).
  3. Click Minify to strip all non-essential whitespace from the XML.
  4. The validator reports any well-formedness errors with their line and column numbers.

XML is the backbone of many enterprise data formats — SOAP web services, SVG graphics, RSS/Atom feeds, Android resources, Office Open XML (docx/xlsx), and Maven/Gradle build files. This formatter validates well-formedness, pretty-prints for human readability, and minifies for wire transmission — all using the browser's native DOMParser for reliable, spec-compliant parsing.

Well-Formed vs Valid XML

Well-formed XML follows basic structural rules: exactly one root element, all elements properly nested and closed, attribute values always quoted, no illegal characters. Valid XML additionally conforms to a DTD (Document Type Definition) or XML Schema (XSD). This formatter checks well-formedness — it does not validate against a schema. Most data interchange scenarios require only well-formedness.

Frequently Asked Questions

What makes XML not well-formed?

Common causes: unclosed tags (<item> without </item>); tags not properly nested (overlapping); more than one root element; missing quotes around attribute values; reserved characters (<, &) in text content without escaping; or an invalid XML declaration at the top.

What is the difference between XML and HTML?

HTML is a markup language for human-readable documents; browsers are lenient with malformed HTML. XML is strict — every violation causes a parse error. XHTML is a strict XML-conforming variant of HTML. SVG and MathML are XML vocabularies used inside HTML5 documents.

How do I include a < or & character in XML text?

Use entity references: &lt; for <, &gt; for >, &amp; for &. Inside a CDATA section (<![CDATA[...]]>), these characters can appear literally without escaping.

What is an XML namespace?

A URI that disambiguates element and attribute names from different vocabularies when combined in one document. The namespace is declared with xmlns="uri" or xmlns:prefix="uri". Used extensively in SOAP, SVG, and Office Open XML formats.

See also the XML Validator, XML to JSON, XML Minifier, and the JSON Formatter.