Are there any good (Linux) tools for diffing 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>
link|improve this question
feedback

5 Answers

up vote 6 down vote accepted

One approach would be to first turn both XML files into Canonical XML, and compare the results using diff. For example, xmllint can be used to canonicalize XML.

$ xmllint --c14n one.xml > 1.xml
$ xmllint --c14n two.xml > 2.xml
$ diff 1.xml 2.xml
link|improve this answer
Never knew about the --c14n switch in xmllint. That's handy. – qedi Dec 10 '09 at 20:21
feedback

Diffxml gets the basic functionality correct, though it doesn't seem to offer many options for configuration.

link|improve this answer
It's not quite there yet, but it looks promising at least. – qedi Dec 7 '09 at 17:02
feedback

I use Beyond Compare to compare all types of text based files. They produce versions for Windows and Linux.

link|improve this answer
Plain text comparisons would say the two lines differed, whereas the OP wants them to be reported as the same. – ChrisF Dec 7 '09 at 16:33
i.e. Canonically compare the XML. – Chris W. Rea Dec 9 '09 at 20:08
feedback

No experience with these, just expanding the list:

link|improve this answer
These are generic diff tools, the OP is asking for tools taking into account XML semantics. – kynan Jan 15 at 19:11
feedback

SD Smart Differencer compares documents based on structure as opposed to actual layout.

There's an XML Smart Differencer. For XML, that means matching order of tags and content. It should note that the text string in the specific fragment you indicated was different. It presently doesn't understand the XML notion of tag attributes indicating whether whitespace is normalized vs. significant.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.