I have been learning on jax-rs. My problem is i don't know how to choose either application/XML or text/XML even i read more articles about them in Internet. Can anyone describe it simply like what application/XML support and not? why I should use text/XML?
The text/xml
media type is an alias for the application/xml
media type.
Check the RFC 7303 for details:
9.1. application/xml Registration
Type name: application
Subtype name: xml
[...]
The registration information for
text/xml
is in all respects the same as that given for application/xml above (Section 9.1), except that the "Type name" is "text".
In JAX-RS, you can use the following to support both:
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public Response foo() {
...
}
w3.org recommendation is to use application/xml
text/xml
is already deprecated
I think they answer your question here What's the difference between text/xml vs application/xml for webservice response
In practice it all depends on the value of the Accept header in the HTTP request, we have used it to return prettyfied well formated XML when the request Accept header includes text/xml and minified single lined XML when the request Accept header includes application/xml, when in doubt ask yourself who is going to read the response, an application or a human?
© 2022 - 2024 — McMap. All rights reserved.