Skip to main content

Creates diffs of XML files

Project description

xmldiff

https://travis-ci.org/Shoobx/xmldiff.svg?branch=master https://coveralls.io/repos/github/Shoobx/xmldiff/badge.svg

xmldiff is a library and a command-line utility for making diffs out of XML. This may seem like something that doesn’t need a dedicated utility, but change detection in hierarchical data is very different from change detection in flat data. XML type formats are also not only used for computer readable data, it is also often used as a format for hierarchical data that can be rendered into human readable formats. A traditional diff on such a format would tell you line by line the differences, but this would not be be readable by a human. xmldiff provides tools to make human readable diffs in those situations.

Full documentation is on xmldiff.readthedocs.io

xmldiff is still under rapid development, and no guarantees are done that the output of one version will be the same as the output of any previous version.

Quick usage

xmldiff is both a command-line tool and a Python library. To use it from the command-line, just run xmldiff with two input files:

$ xmldiff file1.xml file2.xml

There is also a command to patch a file with the output from the xmldiff command:

$ xmlpatch file.diff file1.xml

There is a simple API for using xmldiff as a library:

from lxml import etree
from xmldiff import main, formatting

diff = main.diff_files('file1.xml', 'file2.xml',
                       formatter=formatting.XMLFormatter())

There is also a method diff_trees() that take two lxml trees, and a method diff_texts() that will take strings containing XML. Similarly, there is patch_file() patch_text() and patch_tree():

result = main.patch_file('file.diff', 'file1.xml')

Changes from xmldiff 0.6/1.x

  • A complete, ground up, pure-Python rewrite

  • Easier to maintain, the code is less complex and more Pythonic, and uses more custom classes instead of just nesting lists and dicts.

  • Fixes the problems with certain large files and solves the memory leaks.

  • A nice, easy to use Python API for using it as a library.

  • Adds support for showing the diffs in different formats, mainly one where differences are marked up in the XML, useful for making human readable diffs.

    These formats can show text differences in a semantically meaningful way.

  • An output format compatible with 0.6/1.x is also available.

  • 2.0 is currently significantly slower than xmldiff 0.6/1.x, but this will change in the future. Currently we make no effort to make xmldiff 2.0 fast, we concentrate on making it correct and usable.

Contributors

The diff algorithm is based on “Change Detection in Hierarchically Structured Information”, and the text diff is using Google’s diff_match_patch algorithm.

Changes

2.4 (2019-10-09)

  • Added an option to pass pairs of (element, attr) as unique attributes for tree matching. Exposed this option on the command line, too.

2.3 (2019-02-27)

  • Added a simple xmlpatch command and API.

  • Multiple updates to documentation and code style

2.2 (2018-10-12)

  • A workaround for dealing with top level comments and the xml formatter

2.1 (2018-10-03)

  • Changed the substitution unicode character area to use the Private Use Area in BMP(0), to support narrow Python builds

  • Added –unique-attributes argument.

2.1b1 (2018-10-01)

  • Added options for faster node comparisons. The “middle” option is now default, it had very few changes in matches, but is much faster.

  • Implemented a Fast Match algorithm for even faster diffing.

  • Speed improvements through caching

  • Fixed a bug where MoveNode actions sometimes was in the wrong order

  • Added an InsertComment action, as comments require different handling, so it’s easier to deal with them this way. You can still use DeleteNode and UpdateTextIn for them with no special handling.

  • When renaming tags the XMLFormatter will mark them with “diff:rename” instead of making a new tag and deleting the old.

  • Tags will now be moved first, and updated and renamed later, as the new tag name or attributes might not be valid in the old location.

2.0 (2018-09-25)

  • A complete, bottom-up, pure-python rewrite

  • New easy API

  • 100% test coverage

  • New output formats:

    • A new default output format with new actions

    • A format intended to be parseable by anyone parsing the old format.

    • XML with changes marked though tags and attributes

  • xmldiff 2.0 is significantly slower than xmldiff 0.6 or 1.0, the emphasis so far is on correctness, not speed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmldiff-2.4.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xmldiff-2.4-py2.py3-none-any.whl (57.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file xmldiff-2.4.tar.gz.

File metadata

  • Download URL: xmldiff-2.4.tar.gz
  • Upload date:
  • Size: 94.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.16

File hashes

Hashes for xmldiff-2.4.tar.gz
Algorithm Hash digest
SHA256 05bea20ce1f2c9678683bcce0c3ba9981f87d92b709d190e018bcbf047eccf63
MD5 1728f65d01c5cb1f3c3838d489a1569d
BLAKE2b-256 7636a3e41bf7c01f1110d7b5589ca74d2927d3736a5b43ee63053faf3483b991

See more details on using hashes here.

File details

Details for the file xmldiff-2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: xmldiff-2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 57.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.16

File hashes

Hashes for xmldiff-2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 213c2f4c39ed71811a9ceeec1c8bdf2e673e5527261ea11708b3acfa6c2bdb00
MD5 d676c724f7e13838edd8a7dcc8cbe3e7
BLAKE2b-256 36957d9271ae617b6c448fa244b347e4fd43ed5ad1bb35cea282f1c0fa82ea2b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page