XML : Printing XML values to a html page

Ive created a java service which allows users to view data in either XML, Json or String. My problem is that my web page does not display the XML tags on the html page. When inspecting the element, the XML tags are there but they do not get printed to the screen. Any ideas?

Heres a screenshot and also my code.

  public class FindStaff extends HttpServlet {  @Override  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      String sortedDataText = null;      List<StaffInfo> staffInfoList = StaffUtils.findAllStaff();      String format = request.getParameter("format");        if (format.equalsIgnoreCase("json")) {            sortedDataText = "{ \"membersOfStaff\":[ ";            for (int i = 0; i < staffInfoList.size(); i++) {                sortedDataText += "{\"id\":" + "\"" + staffInfoList.get(i).getStaffID() + "\",";              sortedDataText += "\"forename\":" + "\"" + staffInfoList.get(i).getForename() + "\",";              sortedDataText += "\"surname\":" + "\"" + staffInfoList.get(i).getSurname() + "\",";              sortedDataText += "\"address\":" + "\"" + staffInfoList.get(i).getLocation() + "\",";              sortedDataText += "\"phone\":" + "\"" + staffInfoList.get(i).getPhone() + "\",";              sortedDataText += "\"email\":" + "\"" + staffInfoList.get(i).getEmail() + "\"}";                if (staffInfoList.size() - i > 1) {                  sortedDataText += ",";              }          }            sortedDataText += "]}";            System.out.println("JSON DATA:  " + sortedDataText);        } else if (format.equalsIgnoreCase("xml")) {          sortedDataText = "<membersOfStaff>";          for (int i = 0; i < staffInfoList.size(); i++) {                sortedDataText += "<staffMember><id>" + staffInfoList.get(i).getStaffID() + "</id>";              sortedDataText += "<forename>" + staffInfoList.get(i).getForename() + "</forename>";              sortedDataText += "<surname>" + staffInfoList.get(i).getSurname() + "</surname>";              sortedDataText += "<address>" + staffInfoList.get(i).getLocation() + "</address>";              sortedDataText += "<phoneNumber>" + staffInfoList.get(i).getPhone() + "</phoneNumber>";              sortedDataText += "<email>" + staffInfoList.get(i).getEmail() + "</email></staffMember>";            }          sortedDataText += "</membersOfStaff>";          System.out.println("XML DATA:  " + sortedDataText);        } else if (format.equalsIgnoreCase("string")) {            sortedDataText = "membersOfStaff[ ";          for (int i = 0; i < staffInfoList.size(); i++) {                sortedDataText += "id=" + staffInfoList.get(i).getStaffID() + ",";              sortedDataText += "forename=" + staffInfoList.get(i).getForename() + ",";              sortedDataText += "surname=" + staffInfoList.get(i).getSurname() + ",";              sortedDataText += "address=" + staffInfoList.get(i).getLocation() + ",";              sortedDataText += "phoneNumber=" + staffInfoList.get(i).getPhone() + ",";              sortedDataText += "email=" + staffInfoList.get(i).getEmail();                if (staffInfoList.size() - i > 1) {                  sortedDataText += ", \n\n\n";              }          }            sortedDataText += "]";            System.out.println("TEXT DATA:  " + sortedDataText );      }        PrintWriter out = response.getWriter();      out.print(sortedDataText);    }    

My problem is the XML. The json data displays correctly and so does the string data.. Any ideas would be appreciated (Im new to this)

enter image description here

No comments:

Post a Comment