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>"}'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
- Paste your XML, or click Example.
- Choose the indentation: 2 spaces, 4 spaces or a tab.
- Click Format to pretty print or Minify to remove the whitespace between tags. Tick Strip comments to drop comments too.
- If the XML is not well formed, the error shows the line and column to fix.
- Copy the result or download it as a .xml file.
Examples
Input
<note><to>Ada</to><from lang="en">Alan</from><body/></note>
Output
<note> <to>Ada</to> <from lang="en">Alan</from> <body/> </note>
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".