Compare two XML files

Let’s say we have two files:

<!-- first file -->
<?xml version="1.0" encoding="UTF-8"?>
<sometag attr="1" attr2="2">
  Hello
</sometag>
<!-- second file -->
<?xml version="1.0" encoding="UTF-8"?>
<sometag attr2="2" attr="1">
  Hello
</sometag>

After cleaning with xmllint we can compare them.

xmllint --noblanks --c14n file_one.xml >file_one_tmp.xml;\
 xmllint --format -recover file_one_tmp.xml > file_one_canonical.xml
xmllint --noblanks --c14n file_two.xml >file_two_tmp.xml;\
 xmllint --format -recover file_two_tmp.xml > file_two_canonical.xml
diff file_one_canonical.xml file_two_canonical.xml

As you can see, the only difference lays in comments

2c2
< <!-- second file -->
---
> <!-- first file -->

XML files were transformed into normal form (http://en.wikipedia.org/wiki/Canonical%5FXML).