title: Create XML data to be returned in restful webservice in java
body: <p>How do I create my own xml data to be used with Restful web service in Java? I did create a string file using <code>StringBuilder</code> but when I tried consuming at the client side there is always a problem extracting the attributes from it there is always an error.</p>
  
  <p>Listed below is my code;</p>
  
  <pre><code>Employee emp0 = new Employee("David", "Finance");
  Employee emp1 = new Employee("Smith", "HealthCare");
  Employee emp2 = new Employee("Adam", "Information technology");
  Employee emp3 = new Employee("Stephan", "Life Sciences");
  
  map.put("00345", emp0);
  map.put("00346", emp1);
  map.put("00347", emp2);
  map.put("00348", emp3);
  
  @GET
  @Path("{id}")
  @Produces({"application/xml"})
  public String find(@PathParam("id") String id) {
  
      Employee emp = (Employee) map.get(id);
      if (emp != null) {
          StringBuilder br = new StringBuilder();
          br.append("&lt;?xml version='1.0' encoding='UTF-8'?&gt;").append(nl);
          br.append("&lt;Employee&gt;").append(nl);
          br.append("&lt;Emp-ID&gt;").append(id).append(" &lt;/Emp-ID &gt;").append(nl);
          br.append("&lt;Name&gt;").append(emp.getName()).append(" &lt;/Name&gt;").append(nl);
          br.append("&lt;dept&gt;").append(emp.getDept()).append(" &lt;/Department&gt;").append(nl);
          br.append("&lt;/Employee&gt;");
          return br.toString();
      } else {
          return "Unknown id";
      }
  }
  </code></pre>
  
  <p>I have a POJO by the name of Employee with Name and Department as attributes as well. 
  Thanks.</p>