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)?
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With