Class DiffResult

java.lang.Object
eu.maveniverse.domtrip.DiffResult

public class DiffResult extends Object
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 Details

    • DiffResult

      public DiffResult(List<XmlChange> changes)
      Creates a new DiffResult with the given changes.
      Parameters:
      changes - the list of changes
  • Method Details

    • changes

      public List<XmlChange> changes()
      Returns all changes.
      Returns:
      an unmodifiable list of all changes
    • semanticChanges

      public List<XmlChange> semanticChanges()
      Returns only semantic changes that affect the meaning of the XML.
      Returns:
      the list of semantic changes
    • formattingChanges

      public List<XmlChange> formattingChanges()
      Returns only formatting changes that do not affect meaning.
      Returns:
      the list of formatting-only changes
    • changesUnder

      public List<XmlChange> changesUnder(String path)
      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/name will 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()
      Returns true if any changes were detected.
      Returns:
      true if there are changes
    • changesFor

      public List<XmlChange> changesFor(String xpath, Document doc)
      Returns changes affecting elements that match the given XPath expression in the specified document. This enables rich filtering like diff.changesFor("//dependency[scope='test']", afterDoc).
      Parameters:
      xpath - the XPath expression to match elements
      doc - the document to evaluate the expression against
      Returns:
      the list of changes at or under matching elements
      Since:
      1.3.0
    • changesFor

      public List<XmlChange> changesFor(XPathExpression xpath, Document doc)
      Returns changes affecting elements that match the given compiled XPath expression in the specified document.
      Parameters:
      xpath - the compiled XPath expression to match elements
      doc - 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()
      Returns true if any semantic changes were detected.
      Returns:
      true if there are semantic changes
    • hasFormattingChanges

      public boolean hasFormattingChanges()
      Returns true if any formatting changes were detected.
      Returns:
      true if there are formatting-only changes
    • hasAttributeOrderChanges

      public boolean hasAttributeOrderChanges()
      Returns true if 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 true when the diff contains an ChangeType.ATTRIBUTE_MOVED change.

      Returns:
      true if there are attribute order changes
      Since:
      1.5.0
    • toString

      public String toString()
      Overrides:
      toString in class Object