title: HTTP POST Request XML creation
body: <p>I would like to make a HTTP POST request within an Android activity. I (think that I) know how to do so, but my problem is that I have no idea on how to create the XML file. I've tried different ways described in previous posts but I didn't manage to do so.</p>
  
  <p>My xml format is the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;    
  &lt;IAM version="1.0"&gt;
      &lt;ServiceRequest&gt;
          &lt;RequestTimestamp&gt;2012-07-20T11:10:12Z&lt;/RequestTimestamp
          &lt;RequestorRef&gt;username&lt;/RequestorRef&gt;
          &lt;StopMonitoringRequest version="1.0"&gt;
              &lt;RequestTimestamp&gt;2012-07-20T11:10:12Z&lt;/RequestTimestamp&gt;
              &lt;MessageIdentifier&gt;12345&lt;/MessageIdentifier&gt;
              &lt;MonitoringRef&gt;112345&lt;/MonitoringRef&gt;
          &lt;/StopMonitoringRequest&gt;
      &lt;/ServiceRequest&gt;
  &lt;/IAM&gt;
  </code></pre>
  
  <p>I have the following Java code lines written:</p>
  
  <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost(url);
  
  //What to write here to add the above XML lines?
  
  HttpResponse httpResponse = httpClient.execute(httpPost);
  HttpEntity httpEntity = httpResponse.getEntity();
  xml = EntityUtils.toString(httpEntity);
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Although I managed to somehow create the xml using the following lines, the result I've got is not correct.</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  sb.append("&lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?&gt;");
  sb.append("&lt;IAM version'1.0'&gt;");
  sb.append("&lt;ServiceRequest&gt;");
  sb.append("&lt;RequestTimestamp&gt;2012-07-20T12:33:00Z&lt;/RequestTimestamp");
  sb.append("&lt;RequestorRef&gt;username&lt;/RequestorRef&gt;");
  sb.append("&lt;StopMonitoringRequest version='1.0'&gt;");
  sb.append("&lt;RequestTimestamp&gt;2012-07-20T12:33:00Z&lt;/RequestTimestamp&gt;");
  sb.append("&lt;MessageIdentifier&gt;12345&lt;/MessageIdentifier&gt;");
  sb.append("&lt;MonitoringRef&gt;32900109&lt;/MonitoringRef&gt;");
  sb.append("&lt;/StopMonitoringRequest&gt;");
  sb.append("&lt;/ServiceRequest&gt;");
  sb.append("&lt;/IAM&gt;");
  String xmlContentTosend = sb.toString();
  
  StringEntity entity = new StringEntity(xmlContentTosend, "UTF-8");
  httpPost.setEntity(entity);
  httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials("username", "password"), "UTF-8", false));
  
  HttpResponse httpResponse = httpClient.execute(httpPost);
  HttpEntity httpEntity = httpResponse.getEntity();
  xml = EntityUtils.toString(httpEntity);
  </code></pre>
  
  <p>I get back a String file (xml) that it is not the whole answer that I should have. If I use the Firefox's HTTP Resource Test I get the correct answer while with my solution I get a partial one. I managed to receive the same partial answer in HTTP Resource Test when I removed the </p>
  
  <pre><code>&lt;IAM version="1.0"&gt; 
  </code></pre>
  
  <p>line or some other lines (in general when "destroying" the structure of the xml). However I don't know if it is related.</p>
  
  <p><strong>EDIT (Solution Found)</strong>
  Can you spot it? There's a missing ">" at the first RequestTimestamp in the xml structure. I've been copying-pasting the whole day so I haven't mentioned it. Pfff...</p>