Skip to content

XML Formatter & Validator - Pretty Print XML Online

XML input
Formatted XML

Pretty-print and validate XML

SOAP responses, sitemaps, RSS feeds and config exports often arrive on a single line. This formatter puts each element on its own line and indents children under their parents. It also runs the document through the browser's XML parser and shows the error if it is not well-formed.

Nothing important is rewritten

Formatters that rebuild the document from a parsed tree can reorder attributes, switch quote styles or expand &amp; into &. This one works on the source text. Each tag, entity, processing instruction, DOCTYPE, comment and CDATA section is copied as written, and only whitespace between them changes. An element that holds just text or one CDATA block stays on one line, as <price> does below.

How to use it

Paste XML and pick two spaces, four spaces or a tab. A green "Well-formed XML" note under the editor means the parser accepted it; otherwise the error appears above the output. Any XML works the same way: POM files, Android layouts, SVG, sitemaps, Atom feeds.

Example

Input:

<?xml version="1.0" encoding="UTF-8"?><catalog><!-- spring list --><book id="bk101" lang="en"><title>XML Developer's Guide</title><price currency="USD">44.95</price><notes><![CDATA[Use <b>bold</b> sparingly]]></notes></book><book id="bk102"/></catalog>

Output (2 spaces):

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <!-- spring list -->
  <book id="bk101" lang="en">
    <title>XML Developer's Guide</title>
    <price currency="USD">44.95</price>
    <notes><![CDATA[Use <b>bold</b> sparingly]]></notes>
  </book>
  <book id="bk102"/>
</catalog>

Minify XML

Minify removes the whitespace between tags and, if you tick Remove comments, the comments too. Text with real content is kept exactly, including inner spaces, so <name> Jo Bloggs </name> is unchanged. Input and output sizes are shown under the editor.

Common XML errors

  • Mismatched tags: every <tag> needs a matching </tag> with the same case.
  • Unescaped characters: a bare & or < in text must be written as &amp; or &lt;, or wrapped in CDATA.
  • More than one root: an XML document must have exactly one top-level element.
  • Unquoted attributes: attribute values must be in single or double quotes.

Related tools

Convert XML into JSON with the XML to JSON converter, or tidy HTML with the HTML formatter.

Related Tools

Frequently Asked Questions

Does the formatter change my attributes or their order?
No. Each tag is copied exactly as written, including attribute order, quote style and namespace prefixes. Only the whitespace between tags changes.
What happens to CDATA sections and comments?
Both are copied byte for byte. Content inside CDATA is never re-indented, so embedded HTML or scripts come out exactly as they went in. Comments are always kept when formatting; in Minify mode you can tick Remove comments.
How is the XML validated?
Your browser's built-in XML parser (DOMParser) reads the input. If the document is not well-formed, such as an unclosed tag or an unquoted attribute, the parser's message appears under the editor. The wording varies between Chrome, Firefox and Safari. This checks well-formedness only, not a DTD or XSD schema.
Can I format XML that has errors?
Yes. The formatter works on the raw tags rather than a parsed tree, so it still indents a broken document. A missing close tag then shows up as everything after it sitting one level too deep.
Is whitespace in text changed?
Formatting trims the spaces at each end of a text run, and both modes drop text that is only whitespace. For data XML that is harmless. For mixed content such as <p>Hello <b>world</b></p>, the space before <b> is lost, and xml:space="preserve" is not honoured. Keep the original for documents like XHTML, DocBook or Office XML where those spaces matter.