用于 web 服务响应的 text/xml 与 application/xml 之间有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4832357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between text/xml vs application/xml for webservice response
提问by Mike
This is more of a general question about the difference between text/xmland application/xml.
I am fairly new to writing webservices (REST - Jersey). I have been producing application/xmlsince it is what shows up in most tutorials / code examples that I have been using to learn, but I recently found out about text/xmland was wondering what is different about it and when would you use it over application/xml?
这是更多的区别一般问题text/xml和application/xml。我对编写网络服务(REST - Jersey)相当陌生。我一直在制作,application/xml因为它出现在我用来学习的大多数教程/代码示例中,但我最近发现text/xml并想知道它有什么不同,你什么时候会使用它application/xml?
采纳答案by DaveV
This is an old question, but one that is frequently visited and clear recommendations are now available from RFC 7303which obsoletes RFC3023. In a nutshell (section 9.2):
这是一个老问题,但一个经常访问的问题,现在可以从RFC 7303中获得明确的建议,该RFC 7303已经过时了 RFC3023。简而言之(第 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".
回答by Oded
From the RFC (3023), under section 3, XML Media Types:
来自 RFC ( 3023),在第 3 节 XML 媒体类型下:
If an XML document -- that is, the unprocessed, source XML document -- is readableby casual users, text/xmlis 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/xmlis preferable when the XML MIME entity is unreadableby casual users.
如果XML文档-即,未加工的,源XML文档-是可读的由临时用户,文本/ XML优选为application / xml。没有明确支持 text/xml 的 MIME 用户代理(和 Web 用户代理)会将其视为 text/plain,例如,通过将 XML MIME 实体显示为纯文本。 当普通 用户无法读取XML MIME 实体时,Application/xml是首选。
(emphasis mine)
(强调我的)
回答by hardywang
According to this articleapplication/xml is preferred.
根据这篇文章application/xml 是首选。
EDIT
编辑
I did a little follow-up on the article.
我对这篇文章做了一些跟进。
The author claims that the encoding declared in XML processing instructions, like:
作者声称在 XML 处理指令中声明的编码,例如:
<?xml version="1.0" encoding="UTF-8"?>
can be ignored when text/xmlmedia type is used.
text/xml使用媒体类型时可以忽略。
They support the thesis with the definition of text/*MIME type family specification in RFC 2046, specifically the following fragment:
他们通过RFC 2046中text/*MIME 类型系列规范的定义来支持论文,特别是以下片段:
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/xmlMIME 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.
据他们介绍,使用application/xmlMIME 类型时可以避免此类困难。不管是真是假,我都不会去回避text/xml。恕我直言,最好遵循人类可读性(非可读性)的语义,并始终记住指定字符集。
回答by Micha? Kawiecki
application/xmlis seen by svnas binarytype whereas text/xmlas textfile for which a diff can be displayed.
application/xml通过看到svn作为二进制型,而text/xml作为文本为可显示的差异文件。

