Class DiffResult
java.lang.Object
eu.maveniverse.domtrip.DiffResult
The result of comparing two XML documents, containing all detected changes.
Provides methods to filter changes by type (semantic vs. formatting-only) or by path, and to check whether any changes were detected.
Example:
DiffResult diff = XmlDiff.diff(before, after);
// Semantic changes only (ignore whitespace/formatting)
List<XmlChange> semantic = diff.semanticChanges();
// Formatting-only changes
List<XmlChange> formatting = diff.formattingChanges();
// Changes at a specific path
List<XmlChange> depChanges = diff.changesUnder("/project/dependencies");
- Since:
- 1.3.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDiffResult(List<XmlChange> changes) Creates a new DiffResult with the given changes. -
Method Summary
Modifier and TypeMethodDescriptionchanges()Returns all changes.changesFor(XPathExpression xpath, Document doc) Returns changes affecting elements that match the given compiled XPath expression in the specified document.changesFor(String xpath, Document doc) Returns changes affecting elements that match the given XPath expression in the specified document.changesUnder(String path) Returns changes under the specified path prefix.Returns only formatting changes that do not affect meaning.booleanReturnstrueif any changes affecting attribute order were detected.booleanReturnstrueif any changes were detected.booleanReturnstrueif any formatting changes were detected.booleanReturnstrueif any semantic changes were detected.Returns only semantic changes that affect the meaning of the XML.toString()
-
Constructor Details
-
DiffResult
-
-
Method Details
-
changes
-
semanticChanges
-
formattingChanges
-
changesUnder
Returns changes under the specified path prefix.This method uses boundary-aware matching: a change path must either equal the given path exactly, or start with the path followed by
/or/@. For example, path/project/namewill NOT match a change at/project/namespace.- Parameters:
path- the path prefix to filter by- Returns:
- the list of changes under the given path
-
hasChanges
public boolean hasChanges()Returnstrueif any changes were detected.- Returns:
trueif there are changes
-
changesFor
Returns changes affecting elements that match the given XPath expression in the specified document. This enables rich filtering likediff.changesFor("//dependency[scope='test']", afterDoc).- Parameters:
xpath- the XPath expression to match elementsdoc- the document to evaluate the expression against- Returns:
- the list of changes at or under matching elements
- Since:
- 1.3.0
-
changesFor
Returns changes affecting elements that match the given compiled XPath expression in the specified document.- Parameters:
xpath- the compiled XPath expression to match elementsdoc- the document to evaluate the expression against- Returns:
- the list of changes at or under matching elements
- Since:
- 1.3.0
-
hasSemanticChanges
public boolean hasSemanticChanges()Returnstrueif any semantic changes were detected.- Returns:
trueif there are semantic changes
-
hasFormattingChanges
public boolean hasFormattingChanges()Returnstrueif any formatting changes were detected.- Returns:
trueif there are formatting-only changes
-
hasAttributeOrderChanges
public boolean hasAttributeOrderChanges()Returnstrueif any changes affecting attribute order were detected.Attribute order is not considered a semantic difference in XML, but in many real-world use cases (configuration files, generated build metadata etc.) it is desirable to detect reordering separately from other formatting-only changes like whitespace or quote styles.
This method reports
truewhen the diff contains anChangeType.ATTRIBUTE_MOVEDchange.- Returns:
trueif there are attribute order changes- Since:
- 1.5.0
-
toString
-