natural_xml_diff/
lib.rs

1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3
4//! This crate implements a natural XML diff algorithm: given an original
5//! document we will name document A, and an edited version of that document we
6//! will name document B, the diff algorithm can produce a document describing
7//! the differences between A and B.
8//!
9//! Many possible descriptions of a difference exist; this algorithm attempts
10//! to make the diff appear understandable to the reader and be similar to what
11//! be the product of change tracking.
12//!
13//! The diff result is described in a number of ways, but the end product is an
14//! XML document with annotations that describe the differences.
15//!
16//! You can produce a diff by using the [`diff`](fn@diff) function:
17//!
18//! ```rust
19//!
20//! use natural_xml_diff::diff;
21//!
22//! let xml_a = r#"<doc><a/><b/></doc>"#;
23//! let xml_b = r#"<doc><a/><b/><c/></doc>"#;
24//!
25//! let diff = diff(xml_a, xml_b).unwrap();
26//!
27//! assert_eq!(diff,
28//!   r#"<doc xmlns:diff="http://paligo.net/nxd"><a/><b/><c diff:insert=""/></doc>"#);
29//! ```
30//!
31//! The library also exposes a [`NaturalXmlDiff`] struct that offers
32//! functionality to access the details of the diffing algorithm as well as
33//! functionality to verify that the diff produced is correct.
34//!
35//! The algorithm implemented by this library is based on the paper ["Bridging
36//! the gap between tracking and detecting changes on
37//! XML"](https://www.researchgate.net/publication/3943331_Detecting_changes_in_XML_documents).
38//! It is also implemented by the Java-based [jndiff
39//! library](https://jndiff.sourceforge.net/).
40//!
41//! The algorithm in this library is different from the paper in various ways:
42//!
43//! * Text updates are detected by using a fast Levenshtein distance algorithm,
44//!   and are then produced by the `diff-match-patch` algorithm as implemented
45//!   by the [`dissimilar`] crate.
46//!
47//! * Attribute updates are also detected for elements without children, not
48//!   just during the propagation phase.
49mod apply;
50mod comparison;
51mod convenience;
52mod diff;
53mod diffstatus;
54mod edits;
55mod element;
56mod nlcss;
57mod partition;
58mod propagate;
59mod text;
60mod update;
61mod verify;
62mod vtree;
63
64pub use convenience::{apply, diff, NaturalXmlDiff};
65pub use edits::{AttributeChange, Edit, InsertContent, InsertPosition, TextChange};
66pub use vtree::Status;