Skip to content
PithLab

↑↓ to move · Enter to open · Esc to close

XML Formatter, Validator and Minifier

Beautify, validate and minify XML documents.

Use via API

Validate XML, then pretty-print it with consistent indentation or minify it. Errors report the line and column. Send JSON, get JSON back.

POST https://pithlab.com/api/v1/tools/xml-formatter

curl https://pithlab.com/api/v1/tools/xml-formatter \
  -H "Authorization: Bearer $PITHLAB_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input":"<catalog><book id=\"1\"><title>Dune</title><year>1965</year></book></catalog>"}'

Fields and responseOpenAPI documentGet an API key

About the XML Formatter

Pretty print, validate or minify XML in your browser. Choose the indentation, optionally strip comments, and see the line and column of any XML error.

How to use the XML Formatter

  1. Paste your XML, or click Example.
  2. Choose the indentation: 2 spaces, 4 spaces or a tab.
  3. Click Format to pretty print or Minify to remove the whitespace between tags. Tick Strip comments to drop comments too.
  4. If the XML is not well formed, the error shows the line and column to fix.
  5. Copy the result or download it as a .xml file.

Examples

Format with 2 spaces

Input

<note><to>Ada</to><from lang="en">Alan</from><body/></note>

Output

<note>
  <to>Ada</to>
  <from lang="en">Alan</from>
  <body/>
</note>
Minify

Input

<list>
  <item id = "1" >One</item>
  <!-- second -->
  <item id="2">Two</item>
</list>

Output

<list><item id="1">One</item><!-- second --><item id="2">Two</item></list>

Frequently asked questions

Does formatting change my data?

Text inside elements that only contain text is kept exactly. Whitespace-only text between tags is replaced by the new indentation. Text mixed with child elements is trimmed and placed on its own line.

What does the validator check?

It checks that the XML is well formed: tags are closed and nested correctly, attributes are quoted and not repeated, and names are valid. It does not check against a DTD or XML Schema.

Are comments, CDATA and the XML declaration kept?

Yes. Comments, CDATA sections, processing instructions, the declaration and DOCTYPE are all kept. Tick Strip comments to remove comments.

When is minifying XML useful?

Minified XML is smaller to store and send, for example in API requests or config bundles. Avoid it for documents where whitespace between tags matters, such as those using xml:space="preserve".