Formatting an order file without touching its text
Take a small order exported as one line: an XML declaration, then <order id="7">, which holds an <item sku="A1"> with a <name> of Tea and a <qty> of 2. After the item comes a <note> that says "Leave it by the door", with "by" in bold. It is all on one line, so the structure is hard to see at a glance.
Before laying anything out, the tool hands the text to your browser's XML parser. This one is well-formed, so formatting goes ahead. The declaration stays on the first line. <order id="7"> goes on the next line, and the item is indented two spaces below it. Inside the item, <name>Tea</name> and <qty>2</qty> each get one line, indented four spaces. Elements that hold only text stay on one line, because splitting them would add spaces and line breaks to the text itself. Then </item> closes the block, the note comes next, and </order> ends the file. One line has become eight.
Look at the note. It reads <note>Leave it <b>by</b> the door</note>, still on one line, exactly as it came in. The note holds both text and an element, which XML calls mixed content. In mixed content the spaces around <b>by</b> are part of the sentence. If the formatter put <b> on its own line, a program reading the file would see "Leave it", a line break, and some spaces before "by". So mixed content is written back as it is. The same goes for CDATA sections and any element marked xml:space="preserve".
Now break the file. Change the closing tag of the item to </itme>. The parser stops at that line and the tool shows the line and the column where it stopped, with the browser's own message, which says the end tag does not match. Nothing is formatted, so you never see a neat layout of a broken file. Fix the tag and the formatted XML comes back. One line works the same way: it removes the whitespace between tags, keeps the text, and shows how many bytes it saved.
There are limits. The check is for well-formedness only. The tool does not read your XSD schema or DTD, so a document with a misspelled element name that still matches its own closing tag passes. The exact wording of the error message comes from your browser, so Chrome, Firefox and Safari word it differently. And the formatter assumes that whitespace between elements is layout, not data. That is true for almost all data files, but a few formats treat it as content, and for those you should keep the original.