1

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.

Aubin
  • 14,617
  • 9
  • 61
  • 84
  • So what is wrong with the code you have now? presumably you can add the required nodes you want to compare into the values collection and in the filter test whether the passed in node is in the list – jbailie1991 Feb 13 '17 at 23:19
  • node filter and attribute filter is used for ignoring the nodes. I want to pass the nodes that i want to compare and ignore the rest – Anurag Patro Feb 15 '17 at 04:30
  • Well I would stick with the node filter; try creating collections for element names and attributes that you want to compare and use those in your node and attribute filters, as you do with the values object. Assuming that the majority of nodes are to be ignored then you should carry on with that approach – jbailie1991 Feb 15 '17 at 08:59
  • can u help with the condition for it in node filter – Anurag Patro Feb 24 '17 at 09:28

0 Answers0