I am comparing the xml files for a component . There I have some nodes which i need to compare. But I dont need all the nodes to be compared. So i there any way in xmlunit so that I can compare only those particular nodes. I use nodefilter and attribute filter for ignoring certain nodes. the code is
Diff myDiff1 =
DiffBuilder.compare(actual.toString()).withTest(expected.toString())
.ignoreWhitespace()
.ignoreComments()
.checkForSimilar()
.withNodeMatcher( new DefaultNodeMatcher( ElementSelectors.byNameAndText ))
.withNodeFilter( new Predicate<Node>() {
// code to ignore nodes
public boolean test( Node n ) {
String temp = Nodes.getQName(n).getLocalPart();
if (values.contains(temp)) {
// System.out.println(temp);
}
return !( n instanceof Element && values.contains( temp ));
}
})
.withAttributeFilter(new Predicate<Attr>(){
public boolean test( Attr n ) {
// code to ignore Attributes
javax.xml.namespace.QName attrName = Nodes.getQName(n);
// System.out.println(attrName.toString());
QName Temp = new QName();
// System.out.println(Temp.toString()+n.toString());
Boolean temp1 = !values.contains(attrName.toString());
// Boolean temp1 =!attrName.toString().equals("id") ;
// return !attrName.equals(new QName("balType",null,null,"curCode"));
return temp1;
}
})
.build();
But now I want compare only certain nodes which are required.This is because the xml is very large and majority nodes are different but only few nodes are equal.