78
33
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:
<tag att1="one" att2="two">
content
</tag>
<tag att2="two" att1="one">
content
</tag>
1and xmllint ships with OS X – ClintM – 2016-09-20T16:17:39.230
11In case it wasn't obvious, c14n is an abbreviation for canonicalization. – Brandin – 2016-11-08T17:53:30.263
4It is better to execute an additional step before diff - formatting of both XMLs (xmllint --format). Because I've noticed that without this step diff shows more differences than necessary. – ka3ak – 2016-12-09T12:07:03.260
another run with
xmllint --format
may be helpful (see other answers) – törzsmókus – 2019-06-03T06:43:22.69018You can do it in one line too
vimdiff <(xmllint --c14n one.xml) <(xmllint --c14n two.xml)
– Nathan Villaescusa – 2013-03-03T01:53:44.0371Never knew about the --c14n switch in xmllint. That's handy. – qedi – 2009-12-10T20:21:51.837