#25 Qualified values and XMLAssert.assertXpathEvaluatesTo

Java 1.6

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.

<?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);


  • Stefan Bodewig

    Stefan Bodewig - 2008-10-09

    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?

  • Christophe DENEUX

    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.

    XMLAssert.assertXpathEvaluatesTo(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"),
    "//env11:Envelope/env11:Body/env11:Fault/faultcode", faultDocument);

  • Stefan Bodewig

    Stefan Bodewig - 2008-10-20

    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.

  • Stefan Bodewig

    Stefan Bodewig - 2008-10-20
    • milestone: 814134 -->
  • Stefan Bodewig

    Stefan Bodewig - 2014-12-31
    • status: open --> closed-fixed
    • Group: --> Java 1.6

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks