This is more of a general question about the difference between text/xml
and application/xml
.
I am fairly new to writing webservices (REST - Jersey). I have been producing application/xml
since it is what shows up in most tutorials / code examples that I have been using to learn, but I recently found out about text/xml
and was wondering what is different about it and when would you use it over application/xml
?
This is an old question, but one that is frequently visited and clear recommendations are now available from RFC 7303 which obsoletes RFC3023. In a nutshell (section 9.2):
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".
application/xml
and text/xml
. In addition, I consider this part of the abstract: "This specification standardizes ... application/xml ... while defining text/xml ... as alias..." to mean that application/xml
and text/xml
are equivalent and there is no preference of one about the other. –
Gonsalve application/xml
is the one to use by default? Seems to me that the only reason to keep text/xml
at this point is for backwards compatibility given the standardization is happening on application/xml
instead. –
Bookworm From the RFC (3023), under section 3, XML Media Types:
If an XML document -- that is, the unprocessed, source XML document -- is readable by casual users, text/xml is preferable to application/xml. MIME user agents (and web user agents) that do not have explicit support for text/xml will treat it as text/plain, for example, by displaying the XML MIME entity as plain text. Application/xml is preferable when the XML MIME entity is unreadable by casual users.
(emphasis mine)
<a1 d="" g="">
, for example as unreadable by casual users). –
Zabaglione xgsf
tag mean?), then it is readable. –
Zabaglione This is an old question, but one that is frequently visited and clear recommendations are now available from RFC 7303 which obsoletes RFC3023. In a nutshell (section 9.2):
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".
application/xml
and text/xml
. In addition, I consider this part of the abstract: "This specification standardizes ... application/xml ... while defining text/xml ... as alias..." to mean that application/xml
and text/xml
are equivalent and there is no preference of one about the other. –
Gonsalve application/xml
is the one to use by default? Seems to me that the only reason to keep text/xml
at this point is for backwards compatibility given the standardization is happening on application/xml
instead. –
Bookworm According to this article application/xml is preferred.
EDIT
I did a little follow-up on the article.
The author claims that the encoding declared in XML processing instructions, like:
<?xml version="1.0" encoding="UTF-8"?>
can be ignored when text/xml
media type is used.
They support the thesis with the definition of text/*
MIME type family specification in RFC 2046, specifically the following fragment:
4.1.2. Charset Parameter
A critical parameter that may be specified in the Content-Type field
for "text/plain" data is the character set. This is specified with a
"charset" parameter, as in:
Content-type: text/plain; charset=iso-8859-1
Unlike some other parameter values, the values of the charset
parameter are NOT case sensitive. The default character set, which
must be assumed in the absence of a charset parameter, is US-ASCII.
The specification for any future subtypes of "text" must specify
whether or not they will also utilize a "charset" parameter, and may
possibly restrict its values as well. For other subtypes of "text"
than "text/plain", the semantics of the "charset" parameter should be
defined to be identical to those specified here for "text/plain",
i.e., the body consists entirely of characters in the given charset.
In particular, definers of future "text" subtypes should pay close
attention to the implications of multioctet character sets for their
subtype definitions.
According to them, such difficulties can be avoided when using application/xml
MIME type. Whether it's true or not, I wouldn't go as far as to avoid text/xml
. IMHO, it's best just to follow the semantics of human-readability(non-readability) and always remember to specify the charset.
Update: The situation has changed in the new HTTP/1.1 RFC: The default charset of ISO-8859-1 for text media types has been removed; the default is now whatever the media type definition says.
–
Reciprocate application/xml
but if I use an input form element it is a "file" of type text/xml
which does not process properly with my code. How can I convert it to the other format? –
Coral application/xml
is seen by svn
as binary type whereas text/xml
as text file for which a diff can be displayed.
Web browsers display text/plain as plaintext while most browsers will parse application/xml into data tree, with syntax highlighting, or even go further and apply transformation declared using XSLT. Some browsers cut off rendering application/xml as data tree when an error is detected, but will always display text/xml in full regardless of errors in syntax.
© 2022 - 2024 — McMap. All rights reserved.
text/
is meant for humans.application/
is meant for computers – Principal