title: How to avoid encoding of < and > in a Java SOAP client
body: <p>I am trying to call a DotNet based SOAP Webservice from my Java client and the SOAP request XML contains a CDATA xml as the value in <code>&lt;ser:answerFile&gt;</code> tag. The ideal SOAP request would look something like the below:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.intel.com/"&gt;
     &lt;soapenv:Header&gt;
        &lt;ser:SessionHeader&gt;
           &lt;ser:SessionId&gt;6fdd74d0-3405&lt;/ser:SessionId&gt;
        &lt;/ser:SessionHeader&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;ser:SaveProgressForUser&gt;
           &lt;!--Optional:--&gt;
           &lt;ser:userName&gt;TestUser&lt;/ser:userName&gt;
           &lt;!--Optional:--&gt;
           &lt;ser:answerFile&gt;&lt;![CDATA[&lt;AnswerFile Version="2"&gt;&lt;HeaderInfo&gt;&lt;/HeaderInfo&gt;&lt;ps&gt;&lt;p pid="e32ae8d7-017b-4d36-9c4c-09f6822362b3"&gt;&lt;qs&gt;&lt;q qid="b4c31241-c6c9-4013-9740-4cbc520dd10a" SelectedValue="" /&gt;&lt;repeat c="2" guid="32418f0a-7e13-40db-872d-a42e220bfc15"&gt;&lt;qs i="0" guid="b2f16b48-ca3d-4a06-85e8-7373ead7ccfe"&gt;&lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&gt;&lt;/qs&gt;&lt;qs i="1" guid="cb9e34a2-ecd8-4e06-8072-a6cb682fb655"&gt;&lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&gt;&lt;/qs&gt;&lt;/repeat&gt;&lt;/qs&gt;&lt;/p&gt;&lt;/ps&gt;&lt;/AnswerFile&gt;]]&gt;
           &lt;/ser:answerFile&gt;
        &lt;/ser:SaveProgressForUser&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>So, in my Java client, I declare AnswerFile as a string and while invoking the Webservice I set this string using the setter.</p>
  
  <pre><code>String answerFile = "&lt;![CDATA[&lt;AnswerFile Version="2"&gt;&lt;HeaderInfo&gt;&lt;/HeaderInfo&gt;&lt;ps&gt;&lt;p pid="e32ae8d7-017b-4d36-9c4c-09f6822362b3"&gt;&lt;qs&gt;&lt;q qid="b4c31241-c6c9-4013-9740-4cbc520dd10a" SelectedValue="" /&gt;&lt;repeat c="2" guid="32418f0a-7e13-40db-872d-a42e220bfc15"&gt;&lt;qs i="0" guid="b2f16b48-ca3d-4a06-85e8-7373ead7ccfe"&gt;&lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&gt;&lt;/qs&gt;&lt;qs i="1" guid="cb9e34a2-ecd8-4e06-8072-a6cb682fb655"&gt;&lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&gt;&lt;/qs&gt;&lt;/repeat&gt;&lt;/qs&gt;&lt;/p&gt;&lt;/ps&gt;&lt;/AnswerFile&gt;]]&gt;"
  </code></pre>
  
  <p>However, smart that Java is, it encodes the &lt; and > within the string to <code>&amp;lt;</code> and <code>&amp;gt;</code> and my generated request contains the <code>&lt;ser:answerFile&gt;</code> with an encoded value, something like below:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.intel.com/"&gt;
     &lt;soapenv:Header&gt;
        &lt;ser:SessionHeader&gt;
           &lt;ser:SessionId&gt;6fdd74d0-3405&lt;/ser:SessionId&gt;
        &lt;/ser:SessionHeader&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;ser:SaveProgressForUser&gt;
           &lt;!--Optional:--&gt;
           &lt;ser:userName&gt;TestUser&lt;/ser:userName&gt;
           &lt;!--Optional:--&gt;
           &lt;ser:answerFile&gt;&amp;lt;![CDATA[&amp;lt;AnswerFile Version="2"&amp;gt;&amp;lt;HeaderInfo&amp;gt;&amp;lt;ps&amp;gt;&amp;lt;p pid="e32ae8d7-017b-4d36-9c4c-09f6822362b3"&amp;gt;&amp;lt;qs&amp;gt;&amp;lt;q qid="b4c31241-c6c9-4013-9740-4cbc520dd10a" SelectedValue="" /&amp;gt;&amp;lt;repeat c="2" guid="32418f0a-7e13-40db-872d-a42e220bfc15"&amp;gt;&amp;lt;qs i="0" guid="b2f16b48-ca3d-4a06-85e8-7373ead7ccfe"&amp;gt;&amp;lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&amp;gt;&amp;lt;/qs&amp;gt;&amp;lt;qs i="1" guid="cb9e34a2-ecd8-4e06-8072-a6cb682fb655"&amp;gt;&amp;lt;q qid="7834cb57-ba6f-4063-8a02-4925079d7e04" SelectedValue="" /&amp;gt;&amp;lt;/qs&amp;gt;&amp;lt;/repeat&amp;gt;&amp;lt;/qs&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/ps&amp;gt&amp;lt;/AnswerFile&amp;gt;]]&amp;gt;
           &lt;/ser:answerFile&gt;
        &lt;/ser:SaveProgressForUser&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>So, how can I avoid this encoding and pass the answerFile value as is (With <code>&lt;</code> and <code>&gt;</code>).
  I cannot create a document-element object structure and set, coz the setter only accepts a string as per the WSDL.</p>
  
  <p>Any help will be appreciated. Please yell at me if any info is missing in the problem description.</p>
  
  <p>Like I said, I havent used the Document builder approach, instead just a trivial String object to represent the CDATA XML.
  An excerpt of the class can be seen below.</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  
      try {
              String username = "ServiceUser";
              String password = "Help#";
  
              String masquaradeUsername = "TestUser";
  
              NtlmAuthenticator authenticator = new NtlmAuthenticator(username, password);
              Authenticator.setDefault(authenticator);
  
              Platform platform = new Platform();
              PlatformSoap client = platform.getPlatformSoap();
  
              String answerXML = "&lt;![CDATA[&lt;AnswerFile Version=\"2\"&gt;&lt;HeaderInfo&gt;&lt;/HeaderInfo&gt;&lt;ps&gt;&lt;p pid=\"e32ae8d7-017b-4d36-9c4c-09f6822362b3\"&gt;&lt;qs&gt;&lt;q qid=\"b4c31241-c6c9-4013-9740-4cbc520dd10a\" SelectedValue=\"\" /&gt;&lt;repeat c=\"2\" guid=\"32418f0a-7e13-40db-872d-a42e220bfc15\"&gt;&lt;qs i=\"0\" guid=\"b2f16b48-ca3d-4a06-85e8-7373ead7ccfe\"&gt;&lt;q qid=\"7834cb57-ba6f-4063-8a02-4925079d7e04\" SelectedValue=\"\" /&gt;&lt;/qs&gt;&lt;qs i=\"1\" guid=\"cb9e34a2-ecd8-4e06-8072-a6cb682fb655\"&gt;&lt;q qid=\"7834cb57-ba6f-4063-8a02-4925079d7e04\" SelectedValue=\"\" /&gt;&lt;/qs&gt;&lt;/repeat&gt;&lt;/qs&gt;&lt;/p&gt;&lt;/ps&gt;&lt;/AnswerFile&gt;]]&gt;";
  
              String saveGUID = client.saveProgressForUser(masquaradeUsername, answerXML);
  
          } catch(Exception e) {
              LOGGER.info("Exception encountered####");
  
      }
  }
  </code></pre>
  
  <p>Hope this information helps you understand my problem better.</p>