What Content-Type value should I send for my XML sitemap?
我以为我应该发送" text / xml",但是后来我读到我应该发送" application / xml"。 有关系吗? 有人可以解释差异吗?
如果省略charset参数,则text / xml和application / xml之间的区别是默认字符编码:
Text/xml and application/xml behave differently when the charset
parameter is not explicitly specified. If the default charset (i.e.,
US-ASCII) for text/xml is inconvenient for some reason (e.g., bad web
servers), application/xml provides an alternative (see"Optional
parameters" of application/xml registration in Section 3.2).
对于text / xml:
Conformant with [RFC2046], if a text/xml entity is received with
the charset parameter omitted, MIME processors and XML processors
MUST use the default charset value of"us-ascii"[ASCII]. In cases
where the XML MIME entity is transmitted via HTTP, the default
charset value is still"us-ascii".
对于application / xml:
If an application/xml entity is received where the charset
parameter is omitted, no information is being provided about the
charset by the MIME Content-Type header. Conforming XML
processors MUST follow the requirements in section 4.3.3 of [XML]
that directly address this contingency. However, MIME processors
that are not XML processors SHOULD NOT assume a default charset if
the charset parameter is omitted from an application/xml entity.
因此,如果省略charset参数,则text / xml的字符编码为US-ASCII,而对于application / xml,则可以在文档本身中指定字符编码。
现在,Internet上有一个经验法则:"对输出严格,但对输入宽容。"这意味着在通过Internet传输数据时,请确保尽可能满足标准。但是要建立一些机制来忽略错误或猜测何时通过Internet接收和解释数据。
因此,在您的情况下,只需选择两种类型之一(我建议使用application / xml),并确保正确指定使用的字符编码(我建议使用相应的默认字符编码以安全起见,因此在使用application / xml的情况下) UTF-8或UTF-16)。
根据经验,所有Web服务器,代理和客户端浏览器正确处理文档的最安全选择可能是:
根据某些浏览器无法正确实现的RFC 3023规范,内容类型的主要区别在于客户端应如何对待字符编码,如下所示:
对于application / xml,application / xml-dtd,application / xml-external-parsed-entity或application / xml的任何子类型,例如application / atom + xml,application / rss + xml或application / rdf + xml ,字符编码按以下顺序确定:
对于text / xml,text / xml-external-parsed-entity或诸如text / foo + xml之类的子类型,将忽略文档中XML声明的编码属性,并且字符编码为:
大多数解析器都没有实现规范。他们忽略HTTP上下文类型,而只使用文档中的编码。由于存在大量格式错误的文档,因此短期内不太可能更改。
两者都很好。
text / xxx表示如果程序无法理解xxx,则可以以纯文本格式向用户显示文件。 application / xxx表示毫无意义。
请注意,这些内容类型最初是为电子邮件附件定义的,之后才在Web世界中使用。
text / xml适用于对文档有意义的文档,如果不做进一步处理以文本形式显示,application / xml适用于其他所有文档
Every XML entity is suitable for use with the application/xml media
type without modification. But this does not exploit the fact that
XML can be treated as plain text in many cases. MIME user agents
(and web user agents) that do not have explicit support for
application/xml will treat it as application/octet-stream, for
example, by offering to save it to a file.To indicate that an XML entity should be treated as plain text by
default, use the text/xml media type. This restricts the encoding
used in the XML entity to those that are compatible with the
requirements for text media types as described in [RFC-2045] and
[RFC-2046], e.g., UTF-8, but not UTF-16 (except for HTTP).
— http://www.ietf.org/rfc/rfc2376.txt
此处的其他答案解决了XML响应正确的
答:没有。该站点地图规范为https://www.sitemaps.org,使用Google
如果站点地图规范中没有任何评论可以直接解决此问题,我们可以安全地假定与选择任何其他XML文档的