Paste XML, or open an .xml file, and the tool does two things at once. It checks that the document is well-formed, and it prints it either indented so a person can read it or squeezed onto one line so a machine can ship it. Everything happens in your browser. The text is never sent anywhere, which matters when the XML is a configuration file, an invoice or a SOAP message with real data in it.
How to use it
- Paste or type XML into the left box, press "Open a file", or drop a file on the page. A small example is one click away.
- Choose Pretty print or Minify. For pretty printing, pick two spaces, four spaces or a tab, and optionally put each attribute on its own line or sort them A to Z.
- Read the result on the right, then copy it or download it as formatted.xml. "Use as input" feeds the result back in, which is handy for minifying what you just formatted.
If something is wrong, the tool does not guess. It stops at the first problem, says in plain words which rule was broken, shows the line and column, prints that line with a caret under the spot, and offers a button that puts the cursor there.
The checker follows XML 1.0. There must be exactly one root element and no text outside it. Every start tag needs a matching end tag in the right order, attribute values must be quoted, an attribute name can appear only once per element, and < and & may not appear in text or values as themselves: write < and &. Entity references must be one of the five built in (< > & " '), a numeric reference such as ©, or a name that the document's own DOCTYPE declares. A comment may not contain two hyphens in a row, the XML declaration must be the first thing in the file, and a namespace prefix such as s: must be declared with xmlns:s on the element or one of its parents. Control characters such as U+0001 are not allowed anywhere.
This is a syntax check, not validation. The tool does not compare the document with a DTD or an XML Schema, and it never fetches external entities or schemas.
Pretty printing without changing your data
An XML formatter has one dangerous temptation: adding line breaks inside text. In <p>Hello <b>world</b></p> the space after "Hello" is content, and re-indenting the tag would add a space that was never there. So this tool only adds or removes whitespace where the element holds nothing but other elements, comments and processing instructions. An element with text or a CDATA section in it is written exactly as it was, children included. The XML declaration, the DOCTYPE, comments, processing instructions and CDATA are copied character for character, attributes keep their order and their quote marks, and namespace prefixes stay as written. Minifying the pretty printed result gives the same text as minifying the original, and the tests check that on many documents.
Minify
Minify removes the whitespace that only separates things: indentation and line breaks between elements, and blank lines around comments and the declaration. Text inside elements is kept as it is, so a text element such as <name> Ann </name> is not trimmed. Minifying is useful for payloads and for comparing two files, and a pretty printed copy is easier to compare with the diff checker.
Good to know
Browsers also have a built-in XML parser, but each browser words its errors differently and none names the rule or gives a clean line and column. This tool uses its own checker, so the answer is the same everywhere. Size limit: five million characters. For data in other formats, see the JSON formatter, the CSV and JSON converter and the SQL formatter.