Class DiffResult


  • public class DiffResult
    extends java.lang.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:
    XmlDiff, XmlChange
    • Constructor Summary

      Constructors 
      Constructor Description
      DiffResult​(java.util.List<XmlChange> changes)
      Creates a new DiffResult with the given changes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<XmlChange> changes()
      Returns all changes.
      java.util.List<XmlChange> changesFor​(XPathExpression xpath, Document doc)
      Returns changes affecting elements that match the given compiled XPath expression in the specified document.
      java.util.List<XmlChange> changesFor​(java.lang.String xpath, Document doc)
      Returns changes affecting elements that match the given XPath expression in the specified document.
      java.util.List<XmlChange> changesUnder​(java.lang.String path)
      Returns changes under the specified path prefix.
      java.util.List<XmlChange> formattingChanges()
      Returns only formatting changes that do not affect meaning.
      boolean hasAttributeOrderChanges()
      Returns true if any changes affecting attribute order were detected.
      boolean hasChanges()
      Returns true if any changes were detected.
      boolean hasFormattingChanges()
      Returns true if any formatting changes were detected.
      boolean hasSemanticChanges()
      Returns true if any semantic changes were detected.
      java.util.List<XmlChange> semanticChanges()
      Returns only semantic changes that affect the meaning of the XML.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DiffResult

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

      • changes

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

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

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

        public java.util.List<XmlChange> changesUnder​(java.lang.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 java.util.List<XmlChange> changesFor​(java.lang.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 java.util.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object