How to choose either Application/XML or Text/XML as mediatype?
Asked Answered
P

3

6

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?

Proprioceptor answered 30/6, 2017 at 8:40 Comment(0)
L
3

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

[...]

9.2. text/xml Registration

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() {
    ...
}
Laster answered 21/3, 2018 at 23:39 Comment(0)
S
3

w3.org recommendation is to use application/xml

text/xml is already deprecated

Southerly answered 31/12, 2020 at 20:25 Comment(0)
K
1

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?

Kippie answered 21/3, 2018 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.