CompareOnline4U.

Home › Guides

How to compare two XML files and find the differences

XML Compare — open the free tool →

XML files rarely change in a tidy way. One version comes from an API as a single minified line, the other was saved by an editor with tabs, and a third tool writes the same attributes in a different order. A plain line-by-line diff then marks almost everything as changed, and the one value you care about gets lost.

The fix is simple: normalize first, then compare. This guide shows how, with four methods.

Why a plain diff struggles with XML

Method 1: Compare XML online (fastest)

  1. Open XML Compare.
  2. Paste the original XML on the left and the changed XML on the right.
  3. Leave Format XML ticked. Both documents are checked for well-formedness and pretty-printed with the same indentation.
  4. Tick Sort attributes if the files come from different tools that order attributes differently.
  5. Click Compare now and use Next change to step through changed elements, attribute values and text.

If one side is not well-formed (for example an unclosed tag or a bare &), the tool tells you which side and roughly which line, and compares that side as plain text. The XML is processed in your browser and not uploaded.

Limits: it does not validate against an XSD schema, and a moved element shows as removed in one place and added in another.

Method 2: Notepad++ with the ComparePlus plugin

  1. In Notepad++ go to Plugins → Plugins Admin, install ComparePlus (or the older Compare plugin) and XML Tools.
  2. Open both files and run Plugins → XML Tools → Pretty print on each one.
  3. With the first file active, choose Plugins → ComparePlus → Compare.

Good for: Windows users who already work in Notepad++ and want to edit while comparing.

Method 3: VS Code

Select both files in the Explorer, right-click and choose Compare Selected, or run code --diff old.xml new.xml from a terminal. Format both files first with Format Document (this needs an XML extension installed) so indentation matches.

Method 4: Command line with xmllint

On Linux and macOS, xmllint (from libxml2) can normalize both files before a normal diff:

xmllint --format old.xml > old.fmt.xml
xmllint --format new.xml > new.fmt.xml
diff -u old.fmt.xml new.fmt.xml

To also ignore attribute order, canonicalize first (Canonical XML puts attributes in a fixed order), then format:

xmllint --c14n old.xml | xmllint --format - > old.norm.xml
xmllint --c14n new.xml | xmllint --format - > new.norm.xml
diff -u old.norm.xml new.norm.xml

Good for: scripts, CI checks and very large files.

Which method should you use?

Tips for a clean XML comparison

XML Compare — open the free tool →

Frequently asked questions

Why does my XML diff show every line as changed?

Usually one file is minified (all on one line) or uses different indentation. Format both files with the same indentation first; the online XML Compare does this automatically when Format XML is on.

Does attribute order matter when comparing XML?

No. In XML, attribute order has no meaning, so <item id="1" type="a"/> and <item type="a" id="1"/> are equivalent. Sort attributes (or canonicalize) before comparing so this is not reported as a change.

Can I compare XML files in Notepad++?

Yes. Install the ComparePlus (or Compare) plugin from Plugins → Plugins Admin, open both files and run Plugins → ComparePlus → Compare. Pretty-print both files first with the XML Tools plugin for a cleaner result.

Is it safe to compare XML online?

It depends on the tool. CompareOnline4U formats and compares the XML in your browser, so the files are not uploaded to a server.

More guides

How to compare two JSON files or API responsesDiff two JSON objects quickly: format minified JSON, line up keys and spot changed values. Free browser-based method for developers and testers.How to compare two Word documents and find every changeGot a revised Word file without tracked changes? Learn 3 ways to compare two .docx documents, including a free online method that keeps files private.How to compare two PDF files for differencesFind what changed between two PDF versions of a contract, invoice or report. Step-by-step free method, plus what to do with scanned PDFs.How to compare two Excel files and find differencesCompare two Excel workbooks without VLOOKUP. Free online method, an Excel formula method, and tips to make rows line up correctly.

← All comparison tools