The Python 3 script xdiff.py compares XML files for structural or textual differences.
Added tag 2.1 for changeset e9e390cd1b3c
add option "-C" ("--force-color")
minor edit in README.md

heads

default
browse log
2.1
browse .tar.gz

clone

read-only
https://hg.sr.ht/~nolda/xdiff
read/write
ssh://hg@hg.sr.ht/~nolda/xdiff

XDiff

xdiff.py is a Python 3 script for comparing XML files. It outputs structural and textual differences -- i.e. differences beyond different attribute orders or different whitespace formatting.

The script is released 'as is' with no warranty under the GNU General Public License, version 2.0.

It requires the following Python 3 packages:

The lxml package internally calls the libxml2 and libxslt C libraries.

On Debian-based systems, the prerequisites can be installed as follows:

sudo apt-get install python3-blessings python3-lxml

Usage:

xdiff.py [-a] [--all-context]
         [-c] [--comments]
         [-C] [--force-color]
         [-i] [--indent]
         [-n] [--no-context]
         [-N] [--no-meta]
         [-q] [--quiet]
         [-w] [--words]
         <XML file 1>
         <XML file 2>

xdiff.py [-v] [--version]

xdiff.py [-h] [--help]

The output of xdiff.py mimics the unified format of GNU diff, with three context lines by default. The -a option outputs all context lines, while the -n option outputs none. The option -N suppresses metadata output (files header and hunk numbers). If the option -i is set, the diff is constructed from indented XML trees. The option -w option compares the content word-wise (one word per line). Comments in the XML files are ignored unless the -c option is used. The -C option preserves color and formatting codes when piping output through GNU less and similar programs.

The -q suppresses output altogether, but still returns the exit status (1 if there are structural or textual differences, 0 if there are none, and 2 for errors).

Andreas Nolda (andreas@nolda.org)