Package: xmldiff
xmldiffxmldiffis 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.xmldiffprovides tools to make human readable diffs in those situations.Full documentation is onxmldiff.readthedocs.ioxmldiffis 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 usagexmldiffis both a command-line tool and a Python library.
To use it from the command-line, just runxmldiffwith two input files:$ xmldiff file1.xml file2.xmlThere is also a command to patch a file with the output from thexmldiffcommand:$ xmlpatch file.diff file1.xmlThere is a simple API for usingxmldiffas 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 methoddiff_trees()that take two lxml trees,
and a methoddiff_texts()that will take strings containing XML.
Similarly, there ispatch_file()patch_text()andpatch_tree():result = main.patch_file('file.diff', 'file1.xml')Changes fromxmldiff0.6/1.xA complete, ground up, pure-Python rewriteEasier 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 thanxmldiff0.6/1.x,
but this will change in the future.
Currently we make no effort to makexmldiff2.0 fast,
we concentrate on making it correct and usable.ContributorsLennart Regebro,regebro@gmail.com(main author)Stephan Richter,srichter@shoobx.comAlbertas Agejevas,alga@shoobx.comGreg Kempe,greg@laws.africaFilip Demski,glamhoth@protonmail.comThe diff algorithm is based on “Change Detection in Hierarchically Structured Information”,
and the text diff is using Google’sdiff_match_patchalgorithm.Changes2.6.3 (2023-05-21)And there was a namespace bug in the patch as well. #1182.6.2 (2023-05-21)Solved an error in the xmlformatter when using default namespaces. #892.6.1 (2023-04-05)#108: Fixed an error that happens if using namespaces like ns0 or ns1.2.6 (2023-04-03)AddedInsertNamespaceandDeleteNamespaceactions for better handling
of changing namespaces. Should improve any “Unknown namespace prefix”
errors. Changing the URI of a a namespace prefix is not supported, and will
raise an error.2.6b1 (2023-01-12)Used geometric mean for the node_ratio, for better handling of simple nodes.Added an experimental –best-match method that is slower, but generate
smaller diffs when you have many nodes that are similar.The -F argument now also affects the –fast-match stage.2.5 (2023-01-11)Make it possible to adjust the attributes considered when comparing nodes.Python versions 3.7 to 3.11 are now supported.Improved node matching method, that puts more emphasis similarities than
differences when weighing attributes vs children.Added a parameter to return error code 1 when there are differences between the filesAdded a parameter for ignoring attributes in comparison.Solved a bug in xmlpatch in certain namespace situations.Added a –diff-encoding parameter to xmlpatch, to support diff-files that are
not in your system default encoding.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 simplexmlpatchcommand and API.Multiple updates to documentation and code style2.2 (2018-10-12)A workaround for dealing with top level comments and the xml formatter2.1 (2018-10-03)Changed the substitution unicode character area to use the Private Use Area
in BMP(0), to support narrow Python buildsAdded –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 cachingFixed a bug where MoveNode actions sometimes was in the wrong orderAdded 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 rewriteNew easy API100% test coverageNew output formats:A new default output format with new actionsA format intended to be parseable by anyone parsing the old format.XML with changes marked though tags and attributesxmldiff 2.0 is significantly slower than xmldiff 0.6 or 1.0,
the emphasis so far is on correctness, not speed.