与org.custommonkey.xmlunit.XMLAssert存在严重问题,我在一个Doc中断言,其中包含以下xml。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: cvc-maxLength-valid: Value 'WFWAFBA' with length = '7' is not facet-valid with respect to maxLength '3' for type 'ValidCode'. </faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
我正在使用以下xmlAssert
XMLAssert.assertXpathExists("//soap:Fault[faultcode='soap:Client']", doc);
我通过外部xPath检查器运行它,它找到了元素。有人能帮忙吗?
非常感谢!
编辑:命名空间设置为
HashMap<String, String> m = new HashMap<String, String>();
m.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);