title: How to create SOAP request with CDATA
body: <p>I am new to SOAP,I want to create SOAP request,as given below  </p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"&gt;
   &lt;SOAP-ENV:Header/&gt;
  &lt;soapenv:Body&gt;
    &lt;tem:RequestData&gt;
       &lt;tem:requestDocument&gt;
          &lt;![CDATA[
          &lt;Request&gt;
             &lt;Authentication CMId="68" Function="1" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR"/&gt;
             &lt;Establishment Id="4297867"/&gt;
          &lt;/Request&gt;
          ]]&gt;
  
       &lt;/tem:requestDocument&gt;
    &lt;/tem:RequestData&gt;
  &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;  
  </code></pre>
  
  <p>Code for creating SOAP request  i have found in tutorial </p>
  
  <pre><code>  MessageFactory mf = MessageFactory.newInstance();
                      SOAPMessage sm = mf.createMessage();
                      SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
                      envelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/");
                      envelope.setPrefix("soapenv");
  
                      envelope.setAttribute("xmlns:tem", "http://tempuri.org/");       
  
                      SOAPBody body = envelope.getBody();
                      body.setPrefix("soapenv");
  
                      SOAPElement requestData = body.addChildElement("RequestData");
                      requestData.setPrefix("tem");
  
                      SOAPElement requestDoc = requestData.addChildElement("requestDocument","tem","http://tempuri.org/");
  
                      requestDoc.addTextNode(" &lt;![CDATA[");
  
                      SOAPElement request = requestDoc.addChildElement("Request");
  
                      SOAPElement authentication = request.addChildElement("Authentication");
                      authentication.setAttribute("CMId", "68");
                      authentication.setAttribute("Guid", "5594FB83-F4D4-431F-B3C5-EA6D7A8BA795");
                      authentication.setAttribute("Password", "poihg321TR");
                      authentication.setAttribute("Function", "1");
  
                       SOAPElement establishment = request.addChildElement("Establishment");
                          establishment.setAttribute("Id", "4297867");
                       requestDoc.addTextNode("]]&gt;");
  
                      System.out.println("\nSoap Request: \n\n\n"+getMsgAsString(sm));  
  </code></pre>
  
  <p>Output I am getting is  when executing the code.</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"&gt;&lt;SOAP-ENV:Header/&gt;&lt;soapenv:Body&gt;&lt;tem:RequestData&gt;&lt;tem:requestDocument xmlns:tem="http://tempuri.org/"&gt; &amp;lt;![CDATA[&lt;Request&gt;&lt;Authentication CMId="68" Function="1" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR"/&gt;&lt;Establishment Id="4297867"/&gt;&lt;/Request&gt;]]&amp;gt;&lt;/tem:requestDocument&gt;&lt;/tem:RequestData&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;  
  </code></pre>
  
  <p>The problem is   </p>
  
  <pre><code>&lt;![CDATA[     ]]&gt;  is displaying like  &amp;lt;![CDATA[ and ]]&amp;gt;  
  </code></pre>
  
  <p>And my Server is not accepting this request.</p>