All Tools

XML Formatter and Validator: Beautify or Minify XML

Indent XML with 2 spaces, 4 spaces or tabs, minify it, or check that it is well-formed with line and column errors. Comments, CDATA, namespaces and the declaration are kept. Nothing is uploaded.

Mode
Indent

Leaves <!-- comments --> out of the result.

0 characters, 0 bytes

0 characters, 0 bytes


About the XML Formatter and Validator

The XML Formatter turns compact or messy XML into readable, indented markup, shrinks it back down again, and tells you where it is broken. Paste XML on the left and the result appears on the right as you type. Choose Format to indent with 2 spaces, 4 spaces or a Tab, Minify to remove the whitespace between tags, or Validate to check that the document is well-formed without producing any output.

Your XML never leaves your device. It is parsed by the XML parser built into your browser and written back by code on this page, so nothing is uploaded, logged or stored. That makes the tool fine for configuration files, SOAP messages, sitemaps and feeds that you would rather keep private.

How to use it

Steps

  1. Paste or type XML into XML.
  2. Pick a Mode. The default is Format with two spaces.
  3. In Format or Minify mode, turn on Remove comments to leave comments out.
  4. Read the note under the result: the number of lines, the size before and after minifying, or the root element and element count when validating.
  5. Press Copy or Download .xml to take the result with you.

What is kept

The formatter reads the document into a tree and writes every node back, so nothing is guessed from the text. Elements, attributes, namespace declarations and prefixes, comments, CDATA sections, processing instructions, the <!DOCTYPE> line and the <?xml ... ?> declaration all appear in the output. Characters such as &, < and " are escaped again, so the result is still well-formed XML.

Mixed content is left alone

In XML, the spaces inside an element that mixes text and tags are part of the text. Reindenting <p>Hello <b>big</b> world</p> would add line breaks and spaces to the paragraph's text, so the tool writes such an element on one line exactly as given, in both Format and Minify modes. Elements with xml:space="preserve" are written unchanged for the same reason. Whitespace between elements that contain no text of their own is treated as layout and replaced.

Errors that say where

When the XML is not well-formed, the tool shows the browser parser's message with the line and column it reported, and the offending line with a caret under that column. For <b attr=x/> the parser complains that the attribute value is not quoted. Common causes are a missing closing tag, tags closed in the wrong order, an unescaped &, a second root element and unquoted attribute values. If you only need the check, the XML Validator page opens in Validate mode.

Limits

Only well-formedness is checked; no DTD or XML Schema is loaded. Entities declared in an internal DTD are expanded to their text and the internal subset is not repeated. Browsers word their errors differently, so the exact message and column can vary. For HTML, which has its own looser rules, use the HTML Formatter, and for JSON the JSON Formatter.

Open-source credits

Frequently asked questions

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

Well-formed XML follows the syntax rules of XML 1.0: one root element, every tag closed and nested correctly, attribute values quoted and special characters escaped. Valid XML is also well-formed and additionally matches a DTD or schema. This tool checks well-formedness only; it does not load a DTD or schema.

Why are some elements not indented?

When an element mixes text and child elements, such as a paragraph with a bold word, the spaces between them are part of the text. Adding line breaks there would change the content, so the tool writes such elements on one line exactly as given. Elements marked xml:space="preserve" are kept as they are too.

Why do the line and column of an error differ between browsers?

Each browser uses its own XML parser and reports errors in its own words. Some point to the start of the broken token, others to the character where the parser gave up. The tool shows the position the parser reported and the line it refers to.

Does formatting change my data?

Only whitespace between tags changes. Text, attributes, comments, CDATA sections, processing instructions, namespaces and the XML declaration are written back. Entity references such as &copy; defined in an internal DTD are expanded to their text, and the internal DTD itself is not repeated in the output.

Is my XML uploaded?

No. The text is parsed by the XML parser built into your browser and formatted on the page. Nothing is uploaded or stored, so configuration files and API payloads stay on your device.

Other related tools