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