开发者

What is the difference between serving a page as text/xml and application/xhtml+xml?

What is the difference between serving a page as text/xml and application/xhtml+xml 开发者_运维问答?


Quote from the specification:

The 'application/xhtml+xml' media type [RFC3236] is the primary media type for XHTML Family documents. 'application/xhtml+xml' should be used for serving XHTML documents to XHTML user agents (agents that explicitly indicate they support this media type). This media type must be used when writing documents using XHTML Family document types that add elements and attributes from foreign namespaces, such as XHTML+MathML [XHTML+MathML].

So use application/xhtml+xml to serve your XHTML pages if the client supports it, otherwise you could use text/html.

Another quote from the specification:

  1. If the Accept header explicitly contains application/xhtml+xml (with either no "q" parameter or a positive "q" value) deliver the document using that media type.

  2. If the Accept header explicitly contains text/html (with either no "q" parameter or a positive "q" value) deliver the document using that media type.

  3. If the accept header contains "* /*" (a convention some user agents use to indicate that they will accept anything), deliver the document using text/html.

In other words, requestors that advertise they support XHTML family documents will receive the document in the XHTML media type, and all other requestors that (at least claim to) support HTML or "everything" will receive the document using the HTML media type. Dealing with user agents that satisfy none of these criteria is outside the scope of this document.

When an XHTML document does NOT adhere to the guidelines, it should only be delivered as media type application/xhtml+xml.

text/xml should not be used for serving XHTML web pages. You could use it to serve other XML documents that do not represent XHTML.


Technically, the only difference is that text/xml documents' encoding should default to US-ASCII (if there's no encoding specified in the HTTP header or source), but in application/xml and */*+xml, UTF-8 is the default encoding. I think no browser adheres to this.

The application/xhtml+xml MIME type should be primarily used for XHTML (and for SVG, you should use image/svg+xml). However, in practice, there is no difference between these MIME types because browsers use the same XML parser for all XML-related MIME types.

Remember that application/xhtml+xml doesn't say anything about the content of the document. You're still required to specify xmlns="http://www.w3.org/1999/xhtml" attribute for elements which belong to the XHTML namespace. Otherwise they will be treated as generic XML elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜