I thought I should send "text/xml", but then I read that I should send "application/xml". Does it matter? Can someone explain the difference?
相关问题
- Illegal to have multiple roots (start tag in epilo
- Newtonsoft DeserializeXNode expands internal array
- how to use special characters like '<'
- XML - XSLT - document() function inside count() fu
- convert logback.xml to log4j.properties
相关文章
- Creating XML Elements without namespace declaratio
- Get Attribute Value From Simple XML Using JQuery /
- Directly signing an Office Word document using XML
- When sending XML to JMS should I use TextMessage o
- Fragment Content Overlaps Toolbar and Bottom Navig
- Getting “Error: Missing Constraints in ConstraintL
- Why my javascript code is not executing and says n
- xslt localization
both are fine.
text/xxx means that in case the program does not understand xxx it makes sense to show the file to the user as plain text. application/xxx means that it is pointless to show it.
Please note that those content-types were originally defined for E-Mail attachment before they got later used in Web world.
text/xml is for documents that would be meaningful to a human if presented as text without further processing, application/xml is for everything else
— http://www.ietf.org/rfc/rfc2376.txt
Other answers here address the general question of what the proper
Content-Type
for an XML response is, and conclude (as with What's the difference between text/xml vs application/xml for webservice response) that bothtext/xml
andapplication/xml
are permissible. However, none address whether there are any rules specific to sitemaps.Answer: there aren't. The sitemap spec is https://www.sitemaps.org, and using Google
site:
searches you can confirm that it does not contain the words or phrases mime, mimetype, content-type, application/xml, or text/xml anywhere. In other words, it is entirely silent on the topic of whatContent-Type
should be used for serving sitemaps.In the absence of any commentary in the sitemap spec directly addressing this question, we can safely assume that the same rules apply as when choosing the
Content-Type
of any other XML document - i.e. that it may be eithertext/xml
orapplication/xml
.The difference between text/xml and application/xml is the default character encoding if the charset parameter is omitted:
For text/xml:
For application/xml:
So if the charset parameter is omitted, the character encoding of text/xml is US-ASCII while with application/xml the character encoding can be specified in the document itself.
Now a rule of thumb on the internet is: “Be strict with the output but be tolerant with the input.” That means make sure to meet the standards as much as possible when delivering data over the internet. But build in some mechanisms to overlook faults or to guess when receiving and interpreting data over the internet.
So in your case just pick one of the two types (I recommend application/xml) and make sure to specify the used character encoding properly (I recommend to use the respective default character encoding to play safe, so in case of application/xml use UTF-8 or UTF-16).
As a rule of thumb, the safest bet towards making your document be treated properly by all web servers, proxies, and client browsers, is probably the following:
In terms of the RFC 3023 spec, which some browsers fail to implement properly, the major difference in the content types is in how clients are supposed to treat the character encoding, as follows:
For application/xml, application/xml-dtd, application/xml-external-parsed-entity, or any one of the subtypes of application/xml such as application/atom+xml, application/rss+xml or application/rdf+xml, the character encoding is determined in this order:
For text/xml, text/xml-external-parsed-entity, or a subtype like text/foo+xml, the encoding attribute of the XML declaration within the document is ignored, and the character encoding is:
Most parsers don't implement the spec; they ignore the HTTP Context-Type and just use the encoding in the document. With so many ill-formed documents out there, that's unlikely to change any time soon.