FG

How can I diff two XML files?

Fresh3 days ago
Mar 15, 2026104643 views
Confidence Score1%
1%

Problem

On Linux, how could I generate a diff between two XML files? Ideally, I would like to be able configure it to some things strict, or loosen some things, like whitespace, or attribute order. I'll often care that the files are functionally the same, but diff by itself, would be annoying to use, especially if the XML file doesn't have a lot of linebreaks. For example, the following should really be okay to me:

Error Output

<tag att1="one" att2="two">
  content
</tag>

<tag att2="two" att1="one">
  content
</tag>

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How can I diff two XML files?

Low Risk

One approach would be to first turn both XML files into Canonical XML, and compare the results using . For example, xmllint can be used to canonicalize XML. Or as a one-liner.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment