~nolda/xdiff

A Python script for comparing XML files for structural or textual differences.
~nolda/xdiff

New hg repository added

3 years ago
~nolda/xdiff

New ticket tracker added

3 years ago

#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.

#Requirements

It requires the following Python 3 packages:

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

sudo apt-get install python3-blessings python3-lxml

#Usage

The script is to be used as follows:

usage: xdiff.py [-h] [-a] [-C] [-i] [-n] [-N] [-p] [-P] [-q] [-v] [-w]
                file1 file2

positional arguments:
  file1              XML file 1
  file2              XML file 2

optional arguments:
  -h, --help         show this help message and exit
  -a, --all-context  output all context lines
  -C, --force-color  preserve color and formatting when piping output
  -i, --indent       indent XML trees
  -n, --no-context   output no context lines
  -N, --no-meta      suppress metadata (files header and hunk numbers)
  -p, --pis          preserve processing-instructions in output
  -P, --comments     preserve comments in output
  -q, --quiet        only return exit status
  -v, --version      show program's version number and exit
  -w, --words        compare words

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). Processing instructions and comments in the XML files are ignored unless the options -p and -P are 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)