title: How to prevent REST Assured POST request from dropping XML declaration tag when using an XML content as the request body?
body: <p>I use REST Assured to test uploading an XML file to a database. The back end code is well written and there are no errors. I build the request using REST Assured like this, (the .body() method is from the RequestSpecification class of REST Assured which extends RequestSender class).</p>
  
  <pre><code>response = TestSuite.buildRequest()
              .contentType("text/xml")
              .header("header1")
              .accept("application/json")
              .body(uploadPayload)
              .post(uploadPath)
  </code></pre>
  
  <p>The uploadPayload is an XML file content with the XML declaration tag. Here is an example file content,</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;CATALOG&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Empire Burlesque&lt;/TITLE&gt;
          &lt;ARTIST&gt;Bob Dylan&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;Columbia&lt;/COMPANY&gt;
          &lt;PRICE&gt;10.90&lt;/PRICE&gt;
          &lt;YEAR&gt;1985&lt;/YEAR&gt;
      &lt;/CD&gt;
  &lt;/CATALOG&gt;
  </code></pre>
  
  <p>This content is read from a file in the project directory, this is the method that I use to read this file content and it reads the whole file with all the formatting.</p>
  
  <pre><code>public static String getFileContent(File file) {
  
      if (file == null) return
  
      String s = ""
  
      try {
          FileReader reader = new FileReader(file)
          BufferedReader br = new BufferedReader(reader)
  
          String line
          while ((line = br.readLine()) != null) {
              s = s + line + "\n"
          }
          return s
      } catch (IOException e) {
          throw new IOException("Error getting file content from file.", e)
      }
  }
  </code></pre>
  
  <p>What I do is adding this obtained file content as the request body(the uploadPath variable of the above mentioned request) and send the request. But when the test is executed, the body is shown in the results without the XML declaration tag. But when I print the content the tag is there. This is how the body is shown in the test results (without the XML declaration tag).</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;CATALOG&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Empire Burlesque&lt;/TITLE&gt;
          &lt;ARTIST&gt;Bob Dylan&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;Columbia&lt;/COMPANY&gt;
          &lt;PRICE&gt;10.90&lt;/PRICE&gt;
          &lt;YEAR&gt;1985&lt;/YEAR&gt;
      &lt;/CD&gt;
  &lt;/CATALOG&gt;
  </code></pre>
  
  <p>I need to get the whole body (including the declaration tag) for the request. But for some reason, it is dropped when getting it to the request body. Could someone tell my why and a way to overcome this problem? Your feedback is much appreciated. Thank you.</p>