为什么 MIME 类型适用于 HTML 文本,而 MIME 类型适用于 XHTML 应用程序?

发布于 2025-01-02 15:18:35 字数 73 浏览 1 评论 0原文

是什么使得 XHTML(和其他 XML 语言)应用程序成为文本,而其他基于 SGML 的语言却是文本? XML 文件不是文本文件吗?

What makes XHTML (and other XML languages) applications while other SGML-based languages are text? Aren't XML files text files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戈亓 2025-01-09 15:18:35

XHTML 是 XML 的子集; XML 的媒体类型/mime 是text/xml,而XHTML 的媒体类型/mime 是application/xhtml+xml

一般来说,HTML 本质上被视为解释非常宽松的纯文本。由于 HTML 的垃圾状态声誉,XHTML 的创建是为了迫使 Web 设计人员和 Web 开发人员编写干净的 HTML 代码。 Gecko (Firefox) 和 Presto (Opera) 浏览器可以正确地中断页面并显示格式错误的 XML 解析错误,而 WebKit (Chrome/Safari) 和 Trident(仅限 Internet Explorer 9.0+)则失败并仅停止渲染页面。

用作 text/html 的 XHTML 应用程序不是 XHTML,它是带有 XHTML 文档类型的 HTML。

对于要作为 XHTML 应用程序提供服务的 XHTML 代码,它必须作为 application/xhtml+xml 提供。

XHTML 还旨在向后兼容 HTML。

以下 PHP 代码将查看客户端浏览器发送的标头,如果浏览器支持(所有 Chrome、Safari 3.0+(可能是 1.0))、Mozilla Suite 0.8+/所有 Firefox 和 Opera 7.0,则将该页面作为 XHTML 应用程序提供服务+(可能是 6.0)支持 XHTML。只有 Internet Explorer 8.0 及更早版本拥有不支持 XHTML 的市场份额。 KHTML 浏览器(Konqueror)确实支持 XHTML,但是我认为 4.4 确实/没有向服务器提供正确的标头。

<?php
$http_accept_xhtml = stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml');

if ($http_accept_xhtml) {$mime = 'application/xhtml+xml';}
else {$mime = 'text/html';}

header('Content-Type: '.$mime);
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>

如果您足够聪明,能够在遇到错误时修复错误,那么 XHTML 比 HTML 好得多。它更严格,但这就是重点,更不用说主观性了。 XHTML 中的 X 代表可扩展,因此如果您仔细阅读一下,它会在 HTML 之前支持 SVG 和其他语言。

XHTML is a subset of XML; XML's media type/mime is text/xml while XHTML's media type/mime is application/xhtml+xml.

Generally HTML is essentially treated like plain text that is interpreted very loosely. Because HTML's junk status reputation XHTML was created to force web designers and web developers to code clean HTML. Gecko (Firefox) and Presto (Opera) browsers correctly break the page and display a malformed XML parse error whereas WebKit (Chrome/Safari) and Trident (Internet Explorer 9.0+ only) fail at failing and merely stop rendering the page.

An XHTML application served as text/html is NOT XHTML, it's HTML with an XHTML doctype.

For XHTML code to be served as an XHTML application it must be served as application/xhtml+xml.

XHTML is also intended to be backwards compatible with HTML.

The following PHP code will look at the headers sent by the client's browser and serve the page as an XHTML application if the browser supports it (all Chrome, Safari 3.0+ (maybe 1.0)), Mozilla Suite 0.8+/all Firefox and Opera 7.0+ (possibly 6.0) support XHTML. Only Internet Explorer 8.0 and older have any market share that does not support XHTML. KHTML browsers (Konqueror) DO support XHTML however I think 4.4 does/did not serve the correct header to the server.

<?php
$http_accept_xhtml = stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml');

if ($http_accept_xhtml) {$mime = 'application/xhtml+xml';}
else {$mime = 'text/html';}

header('Content-Type: '.$mime);
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>

XHTML is way better than HTML if you're intelligent enough to fix errors when you come across them. It's stricter but that's the point, much less subjectivity. The X in XHTML stands for extensible so it supported SVG and other languages before HTML did if you do a bit of reading.

无名指的心愿 2025-01-09 15:18:35

对于多种数据,有多种可接受的 MIME 类型。例如,XML 可以是 text/xml 或 application/xml (http://tools.ietf.org/html/rfc3023)。

HTTP 充满了多种正确的做事方式;它是许多人设计和使用的副产品。它也在不断发展。一般来说,即使只有一种设计方法,也可以有多种使用方法,并且在有足够多的人接受后,这些方法就成为事实上的标准。

如果您没有发现任何问题,说您的 XHTML 和 SGML 都是“应用程序”,并且一切仍然有效并且让您更高兴,那就去做吧。

There are several acceptable MIME types for many kinds of data. For instance, XML could be either text/xml or application/xml (http://tools.ietf.org/html/rfc3023).

HTTP is full of multiple correct ways to do stuff; it's a byproduct of being designed and used by so many people. It's also constantly evolving. Generally, even if there was only one way to design something, there can be many ways in which it was used, and these become de facto standards after enough people pick up on them.

If you don't find any problems with saying that your XHTML and SGML are both "applications" and everything still works and it makes you happier, go for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文