title: NAMESPACE_ERR after using setNamespaceAware
body: <p>I'm getting this error: <strong>org.w3c.dom.DOMException: NAMESPACE_ERR</strong></p>
  <p>I have made use of <code>documentBuilderFactory.setNamespaceAware(true)</code>, but I'm still getting the error.</p>
  <p>Firstly, I used JAXB to marshal the body of my SOAP request:</p>
  <pre><code>JAXBContext jaxbContext = JAXBContext.newInstance(CelsiusToFahrenheit.class);
  Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
  StringWriter sw = new StringWriter();
  jaxbMarshaller.marshal(request, sw);
  String xmlBody = sw.toString();
  </code></pre>
  <p>Next, I created the SOAP envelope for the body:</p>
  <pre><code>MessageFactory factory = MessageFactory.newInstance();
  SOAPMessage message = factory.createMessage();
  SOAPPart soapPart = message.getSOAPPart();
  SOAPEnvelope envelope = soapPart.getEnvelope();
  SOAPBody body = envelope.getBody();
  
  Document document = stringToDocument(xmlBody);
  body.addDocument(document);
  </code></pre>
  <p>Then I created the document:</p>
  <pre><code>private static Document stringToDocument(String xml) {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          DocumentBuilder builder;
          try {
              builder = factory.newDocumentBuilder();
              Document doc = builder.parse(new InputSource(new StringReader(xml)));
              return doc;
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  </code></pre>
  <p>For some reason I'm still getting this error:</p>
  <p><em>org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.</em></p>
  <p>This is what the body of my request (xmlBody) looks like:</p>
  <pre><code>&lt;CelsiusToFahrenheit xmlns=&quot;https://www.w3schools.com/xml/&quot;&gt;
        &lt;Celsius&gt;25&lt;/Celsius&gt;
  &lt;/CelsiusToFahrenheit&gt;
  </code></pre>
  <p>Initially my code did not have the <code>documentBuilderFactory.setNamespaceAware(true)</code>.
  I've searched for a solution but unfortunately haven't come across one.</p>