NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces

Java Guy picture Java Guy · Oct 27, 2010 · Viewed 48.9k times · Source

Trying to retrieve the SOAP body from a SOAP response, but getting this error:

NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

Document doc = soapResMsg.getSOAPBody().extractContentAsDocument(); -- Exception is thrown here
org.dom4j.io.DOMReader d4Reader = new org.dom4j.io.DOMReader();
org.dom4j.Document d4doc = d4Reader.read(doc);

Using Saaj1.4

What would be a fix for this?

Answer

Julius picture Julius · Jan 8, 2017

I solved this by making the DocumentBuilderFactory namespace aware:

DocumentBuilderFactory.setNamespaceAware(true)