xmljax-rsmedia-type

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


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?


Solution

  • 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() {
        ...
    }