I try to use XMLAssert.assertXpathEvaluatesTo to check a node value (faulcode value of a SOAP Fault). The value is a qualified value.
XMLAssert.assertXpathEvaluatesTo does not work correctly with qualified value. In the namespace context, if you set a prefix different than the one in your XML document, you can't be able to have a successfull test, expect if you set the prefix provided by your XML document.
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>env:Server</faultcode><faultstring>marche pas</faultstring><detail/></env:Fault></env:Body></env:Envelope>
My namespace context:
final Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("env11", "http://schemas.xmlsoap.org/soap/envelope/");
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
My assert:
XMLAssert.assertXpathEvaluatesTo("env11:Server", "//env11:Envelope/env11:Body/env11:Fault/faultcode", faultDocument);
Hmm, env:Server is just the textual content of an element from a pure XML point of view. How should
XMLUnit know that env: inside some arbitrary text is supposed to be the prefix attached to an XML namespace?
Yes, right, perhaps can you add a new assert to check qualified values: assertXpathEvaluatesTo(QName, String, Document) ? This assert expects that the value is a qualified value, if not the assert fails. If the qualied value is not the expected one, the assert fails.
Example:
XMLAssert.assertXpathEvaluatesTo(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"),
"//env11:Envelope/env11:Body/env11:Fault/faultcode", faultDocument);
not as straight forward as it sounds, but a valid enhancement request.
Not a bug, I hope you agree.
I'm afraid QName doesn't exist prior to Java5 so we'd need to either provide our own abstraction or make the method Java5 only.
added with svn revision 585 - https://sourceforge.net/p/xmlunit/code/585/
Just need to update the user guide.