Search code examples
javaxmlunit-2

How to compare two XML files ignoring specific tags in java JDK7


I am trying to compare the two XML files where certain tags has to be ignored. How can this be achieved? Since I am using JDK 7, lambda expressions cannot be used.


Solution

  • The lambda expression really only is syntactic sugar for an anonymous inner class. The example of Java: How do I ignore certain elements when comparing XML?

    .withNodeFilter(node -> !node.getNodeName().equals(someName))
    

    is really just

    import org.xmlunit.util.Predicate;
    import org.w3c.dom.Node;
    
    .withNodeFilter(new Predicate<Node>() {
        public boolean test(Node node) {
            return !node.getNodeName().equals(someName);
        }
    })
    

    No need for Java8.