What content-type should be used for XML+XSL prese

2019-06-16 02:26发布

问题:

I'm trying to render XML+XSL 2.0 in browser, returning .xml pages with application/xml content type and .xsl pages with text/xml. Safari is complaining for the main document: "Resource interpreted as document but transferred with MIME type application/xml." (but keeps rendering everything just fine).

I want to get rid of this warning message. What content-types should be used for the XML document?

回答1:

I've had success using text/xml with the stylesheet as text/xsl (or perhaps this is OK as text/xml as you have it working). text/xsl is widely recognized, but not "official" (as far as I understand it).

According to RFC 3023: "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."

See https://tools.ietf.org/html/rfc3023#page-16



回答2:

Peeking into the WebKit source, it's easy to see what MIME types are considered valid for each resource type. It's not a very big list.

The following 4 MIME types are supported for "Documents":

  • text/html
  • text/xml
  • text/plain
  • application/xhtml+xml

There are only 2 valid types for stylesheets:

  • text/css
  • text/xsl

Obviously, the text/html, text/plain, and text/css types don't really apply here.

If you're really just interested in silencing the warnings, sending the .xml document as text/xml and the .xsl document as text/xsl should do the trick.

On the other hand, you concede that everything's rendering fine, so you might consider the "if it ain't broke, don't fix it" strategy.



回答3:

Before any transformation i do this in PHP:

header("Content-Type: application/xhtml+xml; charset=utf-8");

the part with uft-8 is important ...



标签: xml xslt