Class XmlDiff
java.lang.Object
eu.maveniverse.domtrip.XmlDiff
XML-aware structural diff engine that compares two documents and detects
both semantic and formatting-only changes.
Because DomTrip preserves all formatting metadata (whitespace, quote styles, entity encoding, empty element style), this diff can uniquely distinguish between changes that affect meaning and changes that are formatting-only. This is a capability no other Java XML library offers.
Basic usage:
Document before = Document.of(oldXml);
Document after = Document.of(newXml);
DiffResult diff = XmlDiff.diff(before, after);
for (XmlChange change : diff.changes()) {
System.out.println(change);
}
// → ELEMENT_ADDED: /project/dependencies/dependency[3]
// → TEXT_CHANGED: /project/version: "1.0" → "1.1"
// → ATTRIBUTE_CHANGED: /project/dependencies/dependency[2]/@scope: "compile" → "test"
Configurable matching:
DiffConfig config = DiffConfig.builder()
.matchBy("dependency", "groupId", "artifactId")
.build();
DiffResult diff = XmlDiff.diff(before, after, config);
- Since:
- 1.3.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DiffResultCompares two documents using default configuration (positional matching).static DiffResultdiff(Document before, Document after, DiffConfig config) Compares two documents using the given configuration.
-
Method Details
-
diff
Compares two documents using default configuration (positional matching).- Parameters:
before- the original documentafter- the modified document- Returns:
- the diff result containing all detected changes
-
diff
Compares two documents using the given configuration.- Parameters:
before- the original documentafter- the modified documentconfig- the diff configuration controlling element matching- Returns:
- the diff result containing all detected changes
-