title: Servlet that receives a XML based request and then make a new XML file to send back as the response
body: <p>I am trying to create a Servlet that receives a XML based request and sends a XML in the response. I am new to Servlet first of all. </p>
  
  <p>I have created the below Servlet in which I thought I am creating a Servlet that receives a XML based request in the <code>doGet method</code> and then in the <code>doPost method</code>, I can parse that XML file and then make a new XML file to send back the response. But I believe my understanding is wrong.</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  
      response.setContentType("application/xml");
      PrintWriter writer = response.getWriter();
      writer.println("&lt;?xml version=\"1.0\"?&gt;");
      writer.println("&lt;request uuid = \"hello\"&gt;");
      writer.println("&lt;app hash = \"abc\"/&gt;");
      writer.println("&lt;app hash = \"def\"/&gt;");
      writer.println("&lt;/request&gt;");
      writer.flush();
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      System.out.println(request);
         //parse the xml file if my understanding is right?
  }
  </code></pre>
  
  <p>Can anyone provide me a simple example of this? I am just trying to create a Servlet that receives a XML based request (I am not sure of this, how can I make a servlet that can receive a XML based request), xml should be like above in my example.</p>
  
  <p>And then parse the above XML file and use some content from that XML file to make a new sample XML file which I will be sending back as the response from that same Servlet.</p>
  
  <p>Any help will be appreciated on this as I am slightly new to Servlet. This is the first time I am working with Servlet.</p>
  
  <p><strong>Update:-</strong></p>
  
  <p>I haven't got a proper answer on this yet. Any simple example will make me understand better. Thanks</p>