Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use application/xml as compared to text/xml?

Tags:

java

xml

jersey

In the web service I've been working on, I've been displaying text to the screen through methods like so in HTML:

@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() 
{
/**Do some stuff
    return "<html> " + "<title>" + "Hello" + "</title>"
            + "<body><h1>" + "Hello World" + "</h1></body></html>";
}

which displays to the screen quite nicely. In order to fit the project description of the project I'm working on, I've been working on moving toward an XML output by building a document, transforming it to a string, and returning the string. Using @Produces(MediaType.TEXT_XML) shows the XML tree like I would expect.

My question comes here: I need to be able to pass this XML data on using what the project description calls a Response Content-Type Header of application/xml;charset=UTF-8. So what would I need to do to accomodate using @Produces(MediaType.APPLICATION_XML) instead of @Produces(MediaType.TEXT_XML)?

like image 874
ZKSteffel Avatar asked Jan 20 '23 15:01

ZKSteffel


2 Answers

Use application/xml for documents meant primarily to be processed by programs. Use text/xml for documents which are also meant for human reading for purposes other than debugging. I believe this is covered in RFC 2046.

like image 72
karmakaze Avatar answered Jan 28 '23 12:01

karmakaze


application/xml is generally the preferred mime type. For text/xml it appears the encoding will generally be treated as us ascii regardless of what is specified in the XML document header (unless otherwise specified in the HTTP headers).

For More Information:

  • http://www.grauw.nl/blog/entry/489
  • http://www.imc.org/ietf-xml-mime/mail-archive/msg00496.html
like image 33
bdoughan Avatar answered Jan 28 '23 12:01

bdoughan