title: JAva SOAP: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces
body: <p>I've seen questions like this but so far they don't help.</p>
  
  <p>I'm currently having an issue setting a prefix for an element within my SOAP body.
  The request I'm trying to build looks like this:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="http://company.org/sendmailaTTACH"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;sen:SendMail&gt;
           &lt;sen:plainbody&gt;?&lt;/sen:plainbody&gt;
        &lt;/sen:SendMail&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Was able to build it to the point of the <code>SendMail</code> object by following <a href="https://stackoverflow.com/a/43316912/5038073">this answer</a>, but when it gets to the part of adding the prefix: <code>&lt;sen:plainbody&gt;</code> i.e adding the <code>sen</code> prefix to <code>plainbody</code> I get the error:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>The <code>SendMail</code> object looks like this: </p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(
          name = "",
          propOrder = {"from", "displayname", "to", "cc", "bcc", "htmlbody", "plainbody", "subject", "imageurl"}
  )
  @XmlRootElement(
          name = "SendMail"
  )
  public class SendMail {
      protected String from;
      protected String displayname;
      protected String to;
      protected String cc;
      protected String bcc;
      protected String htmlbody;
      protected String plainbody;
      protected String subject;
      protected String imageurl;
  
      public SendMail() {
      }
  .
  .
  .
  //getters and setters
  </code></pre>
  
  <p>I'm guessing maybe it's because the plainbody and other fields there are String?</p>
  
  <p>Is there any way around this?</p>
  
  <p>Thank you!</p>