DiffKit / XML compare
XML compare
Paste two XML documents. Both are checked for well-formedness, re-indented and attribute-sorted, so the diff shows real changes rather than formatting.
Why normalise XML before diffing?
Two XML files can carry exactly the same data and still look completely different as text. One has every element on its own line, the other packs three onto one, and a serializer has put the attributes in a different order. A plain line diff would mark almost everything as changed.
DiffKit parses each side with the browser’s own XML parser, prints one element per line with two-space indentation and sorts attributes alphabetically. The diff that follows lines up element for element. In the example, the version bump, the slf4j upgrade and the JUnit 4 to JUnit 5 switch stand out, while the reordered scope and optional attributes do not.
What is kept as-is
- Namespaces and prefixes, exactly as written.
- CDATA sections and processing instructions.
- Comments, unless you tick “Ignore comments”.
Comparing HTML instead? HTML isn’t always well-formed XML, so it has its own HTML compare that uses a forgiving parser.
Questions people ask
Does attribute order matter in XML?
No. The XML 1.0 specification from the W3C says the order of attributes in a start tag is not significant. With “Sort attributes” on, DiffKit orders them alphabetically on both sides so a reordered attribute is not reported as a change.
Why does my XML show an error?
The file must be well-formed: one root element, every tag closed, attribute values quoted and special characters like & escaped. The browser’s XML parser reports the first problem it finds, which is shown above the diff.
Can I compare Maven POMs, Android layouts or SVG files?
Yes, any well-formed XML works, including pom.xml, AndroidManifest.xml, .csproj, SVG, RSS and SOAP messages.
Is whitespace between tags compared?
No. Both documents are re-indented, so whitespace-only text between elements disappears. Whitespace inside text content is trimmed at the ends but otherwise kept.