这是我的代码
Scanner s = new Scanner(new File("ignore.txt"));
final ArrayList<String> list = new ArrayList<String>();
while (s.hasNext()){
list.add(s.next());
}
s.close();
int lengthList = list.size();
final Set<String> values = new HashSet<String>(list);
Diff myDiff1 = DiffBuilder.compare(writer1.toString()).withTest(writer.toString())
.checkForSimilar()
.checkForIdentical()
.ignoreWhitespace()
.normalizeWhitespace()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.withNodeFilter(new Predicate<Node>() {
public boolean test(Node n) {
String temp = Nodes.getQName(n).getLocalPart();
//System.out.println(temp);
return !(n instanceof Element &&
values.contains(temp));
}
})
.withAttributeFilter(new Predicate<Attr>(){
public boolean test(Attr n){
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("answerType") ;
//System.out.println(temp1);
//return !attrName.equals(new QName("balType",null, null, "curCode"));
return temp1;
}
})
.build();
我的 xml 文件是
<ns3:CoreExceptionFault xmlns:ns3="http://core.soayodlee.com">
<faultText>com.yodlee.util.system.ycache.CobrandNotSupportedException: The CobrandCache for the cobrand 10004 is not initialized.</faultText>
</ns3:CoreExceptionFault>
我想忽略 xmlns:ns3 属性。上面的文件 Ignore.txt 包含我需要忽略的所有节点和属性。但是当我添加 xmlns:ns3 时,它并没有忽略该属性。我正在使用 XMLunit 2.2.1