1

I am able to compare 2 xml files using XMLUNIT 2.5 DiffBuilder. I want to ignore certain elements using withNodeFilter. But the withNodeFilter accepts only 1 element. Is there a way to ignore more that one element for comparison.

DiffBuilder.compare(DocB)
.withTest(docA)
.withNodeFilter(node -> !node.getNodeName().equals("metadata")) // need to include more element tags to ignore
.build();
Ben
  • 195
  • 2
  • 10

2 Answers2

3

You can just use logic operators, for example,

.withNodeFilter(node -> !(node.getNodeName().equals("metadata") ||
                          node.getNodeName().equals("comment"))

This will match all nodes which are not metadata or comment.

TheZeus121
  • 449
  • 4
  • 14
0

I think TheZeus121's solution looks good if there are one or two nodes, but if you want to add more than 10 nodes to ignore in xml comparison, then I think this tradition way of keep on adding nodes using '||' or '&&'is not a right approach. So, just I had modified for such kind of approach, please have a look in this link

https://stackoverflow.com/a/68099435/13451711