简而言之,XHTML和HTML的区别是什么?

时间:2021-07-15 15:46:45

I keep being confused about the two. Can someone sum up the key difference(s) and maybe a typical use case very briefly?

我一直对这两个感到困惑。有人能简单地总结一下关键的不同之处,或者一个典型的用例吗?

Is XHTML just more "strict" / clean / XML-y?

XHTML是不是更“严格”/干净/ xml ?

If XHTML is just the "more correct" version of HTML, why should I ever use HTML at all?

如果XHTML只是“更正确”的HTML版本,我为什么要使用HTML呢?

3 个解决方案

#1


7  

XHTML 1.0 is HTML 4.01 reimplemented using XML instead of SGML. This lets you process it with XML tools (but you need to be careful with the output if you want to support IE) and mix in other XML namespaces such as SVG or MathML (unless you want to support IE). Writing XHTML that is HTML compatible is a fair amount of effort and most people who try it screw it up so I suggest sticking to HTML.

XHTML 1.0是使用XML而不是SGML重新实现的HTML 4.01。这使您可以使用XML工具来处理它(但如果您想支持IE,则需要小心处理输出),并混合使用其他XML名称空间,如SVG或MathML(除非您想支持IE)。编写与HTML兼容的XHTML是一项相当大的工作,大多数尝试它的人都把它搞砸了,所以我建议坚持使用HTML。

#2


1  

In a word: syntax.

一个词:语法。

XHTML is HTML that conforms to the XML syntax rules. (Unless I’m missing something, XML itself is just a set of syntax rules.)

XHTML是符合XML语法规则的HTML。(除非我漏掉了什么,否则XML本身就是一组语法规则。)

If I understand correctly, HTML looks a bit like SGML, and looks a bit like XML, but effectively has its own somewhat idiosyncratic syntax rules that are reasonably effectively implemented by the major web browsers, and are now codified in the HTML5 spec (whereas before, they hadn’t been codified outside of the behaviour of the web browsers themselves).

如果我理解正确的话,HTML看上去有点像SGML和XML看上去有点像,但实际上都有自己的有点特殊语法规则,合理有效地由主流web浏览器实现,和现在编纂HTML5规范(之前,他们没有被外部的web浏览器本身的行为)。

#3


-1  

XHTML is more or less HTML 4.x reimplemented in XML (instead of based on SGML directly) which results in some additional features like namespace support that make it easier to extend for problem specific markup while keeping it valid.

XHTML或多或少是HTML 4。x在XML中重新实现(而不是直接基于SGML),这就产生了一些额外的特性,比如名称空间支持,使扩展特定问题的标记变得更容易,同时保持其有效性。

The problem is, that to this point as far as I know no browser actually interprets XHTML as XML completely so it's mostly a bonus for developers who want to operate on the generated markup (since it's XML and can therefor be parsed more easily).

问题是,就我所知,目前还没有任何浏览器将XHTML完全解释为XML,所以对于希望对生成的标记进行操作(因为它是XML,因此可以更容易地解析)的开发人员来说,这是一个额外的好处。

So to keep it simple: XHTML is more strict.

为了保持简单:XHTML更加严格。

#1


7  

XHTML 1.0 is HTML 4.01 reimplemented using XML instead of SGML. This lets you process it with XML tools (but you need to be careful with the output if you want to support IE) and mix in other XML namespaces such as SVG or MathML (unless you want to support IE). Writing XHTML that is HTML compatible is a fair amount of effort and most people who try it screw it up so I suggest sticking to HTML.

XHTML 1.0是使用XML而不是SGML重新实现的HTML 4.01。这使您可以使用XML工具来处理它(但如果您想支持IE,则需要小心处理输出),并混合使用其他XML名称空间,如SVG或MathML(除非您想支持IE)。编写与HTML兼容的XHTML是一项相当大的工作,大多数尝试它的人都把它搞砸了,所以我建议坚持使用HTML。

#2


1  

In a word: syntax.

一个词:语法。

XHTML is HTML that conforms to the XML syntax rules. (Unless I’m missing something, XML itself is just a set of syntax rules.)

XHTML是符合XML语法规则的HTML。(除非我漏掉了什么,否则XML本身就是一组语法规则。)

If I understand correctly, HTML looks a bit like SGML, and looks a bit like XML, but effectively has its own somewhat idiosyncratic syntax rules that are reasonably effectively implemented by the major web browsers, and are now codified in the HTML5 spec (whereas before, they hadn’t been codified outside of the behaviour of the web browsers themselves).

如果我理解正确的话,HTML看上去有点像SGML和XML看上去有点像,但实际上都有自己的有点特殊语法规则,合理有效地由主流web浏览器实现,和现在编纂HTML5规范(之前,他们没有被外部的web浏览器本身的行为)。

#3


-1  

XHTML is more or less HTML 4.x reimplemented in XML (instead of based on SGML directly) which results in some additional features like namespace support that make it easier to extend for problem specific markup while keeping it valid.

XHTML或多或少是HTML 4。x在XML中重新实现(而不是直接基于SGML),这就产生了一些额外的特性,比如名称空间支持,使扩展特定问题的标记变得更容易,同时保持其有效性。

The problem is, that to this point as far as I know no browser actually interprets XHTML as XML completely so it's mostly a bonus for developers who want to operate on the generated markup (since it's XML and can therefor be parsed more easily).

问题是,就我所知,目前还没有任何浏览器将XHTML完全解释为XML,所以对于希望对生成的标记进行操作(因为它是XML,因此可以更容易地解析)的开发人员来说,这是一个额外的好处。

So to keep it simple: XHTML is more strict.

为了保持简单:XHTML更加严格。