比较/对比 HTML、XHTML、XML 和 HTML5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1429065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:51:59  来源:igfitidea点击:

Compare/contrast HTML, XHTML, XML, and HTML5

xmlxhtmlhtml

提问by GiH

Ok, so I'm not quite sure the difference between these languages. Could someone clarify? I know that XML has user-defined tag and html is pre-defined, but thats basically the extent of my knowledge.

好的,所以我不太确定这些语言之间的区别。有人可以澄清吗?我知道 XML 有用户定义的标签,而 html 是预定义的,但这基本上是我的知识范围。

I know that HTML5 is supposed to replace HTML, but wasn't XML supposed to do that as well? Basically, which languages here are a substitute for the other, and which complement? Does XML replace XHTML?

我知道 HTML5 应该取代 HTML,但 XML 不应该也这样做吗?基本上,这里的哪些语言可以替代其他语言,哪些是补充?XML 会取代 XHTML 吗?

回答by Thomas Owens

HTMLis the HyperText Markup Language, which is designed to create structured documents and provide for semantic meaning behind the documents. HTML5 is the next version of the HTML specification.

HTML是超文本标记语言,旨在创建结构化文档并提供文档背后的语义含义。HTML5 是 HTML 规范的下一个版本。

XMLis the Extensible Markup Language, which provides rules for creating, structuring, and encoding documents. You often see XML being used to store data and to allow for communication between applications. It's programming language-agnostic - all of the major programming languages provide mechanisms for reading and writing XML documents, either as part of the core or in external libraries.

XML是可扩展标记语言,它提供用于创建、结构化和编码文档的规则。您经常会看到 XML 用于存储数据并允许应用程序之间进行通信。它与编程语言无关——所有主要的编程语言都提供了读取和写入 XML 文档的机制,作为核心的一部分或在外部库中。

XHTMLis an XML-based HTML. It serves the same function as HTML, but with the same rules as XML documents. These rules deal with the structure of the markup.

XHTML是一种基于 XML 的 HTML。它具有与 HTML 相同的功能,但具有与 XML 文档相同的规则。这些规则处理标记的结构。

回答by GiH

XML is a meta language. A meta language is a language that provides a syntax mechanism for creating other languages without constraining expression through a predefined grammar. XML is defined in the SGML doctype language. Adherence to the strict syntax requirements of XML is called well-formedness, which is a practice of precise accuracy to a stated set of requirements in an effort to achieve uniform processing of a document across various different applications and user agents.

XML 是一种元语言。元语言是一种语言,它提供一种语法机制来创建其他语言,而无需通过预定义的语法来约束表达式。XML 是在 SGML 文档类型语言中定义的。遵守 XML 的严格语法要求称为格式良好,这是一种对规定的要求集精确准确的做法,以努力在各种不同的应用程序和用户代理之间实现对文档的统一处理。

SGML is a meta language like XML and is even the parent of XML. SGML offers a broad form for defining data in uses of syntax without providing a data typing convention. Unlike SGML XML features a rigid and extremely simplified syntax that is not open to confusion. XML also features data type definitions also unlike SGML. Elements in XML provide namespace scope in a lambda fashion, while SGML provides no support for namespaces.

SGML 是一种类似于 XML 的元语言,甚至是 XML 的父语言。SGML 为使用语法定义数据提供了广泛的形式,而无需提供数据类型约定。与 SGML 不同,XML 具有严格且极其简化的语法,不会引起混淆。XML 还具有与 SGML 不同的数据类型定义。XML 中的元素以 lambda 方式提供命名空间范围,而 SGML 不提供对命名空间的支持。

Doctype is an SGML based language that uses a syntax completely unlike XML for defining markup language grammars and broad data type conventions to tell data elements apart from text.

Doctype 是一种基于 SGML 的语言,它使用与 XML 完全不同的语法来定义标记语言语法和广泛的数据类型约定,以将数据元素与文本区分开来。

XML Schema is an XML written language that allows language grammar definitions with precise structural form in addition to specific data typing conventions for elements, structures, and attributes. Languages written in Schema structurally self-aware, unlike SGML vocabularies, so that they know of their own internal requirements at any various point in the structure. Languages defined by schema are able to be immediately open to validation through reference to the Schema document, due to the structural self-awareness, while languages defined in Doctype require unrelated software with static definitions to order to perform validation.

XML Schema 是一种 XML 书面语言,除了元素、结构和属性的特定数据类型约定之外,它还允许具有精确结构形式的语言语法定义。与 SGML 词汇表不同,以 Schema 编写的语言在结构上具有自我意识,因此它们在结构的任何不同点都知道自己的内部需求。由于具有结构的自我意识,schema定义的语言可以通过引用Schema文档立即开放进行验证,而Doctype定义的语言需要具有静态定义的无关软件才能执行验证。

HTML 1.0 was written in English text and is neither SGML or XML.

HTML 1.0 是用英文编写的,既不是 SGML 也不是 XML。

HTML 2 - 4 are written in SGML and feature SGML flexibilities, such as uppercase tags or start tags without a matching closing tag.

HTML 2 - 4 是用 SGML 编写的,具有 SGML 的灵活性,例如大写标签或没有匹配结束标签的开始标签。

XHTML 1.0 is an SGML defined form of the HTML language with some extended requirements to gleam progressive compatibility towards XML syntax.

XHTML 1.0 是一种 SGML 定义的 HTML 语言形式,具有一些扩展要求,以逐步实现对 XML 语法的兼容性。

XHTML 1.1 is the HTML language defined in XML with XML well-formedness requirements.

XHTML 1.1 是在 XML 中定义的 HTML 语言,具有 XML 格式良好的要求。

HTML5, like HTML 1.0, is not defined using any meta language. It is written in English text and moves radically in opposition of the uniform requirements of an XML serialization. HTML5 appears to be created for usability and media delivery without regard for structure or language hierarchies.

HTML5 与 HTML 1.0 一样,没有使用任何元语言进行定义。它是用英文写成的,完全违背了 XML 序列化的统一要求。HTML5 似乎是为可用性和媒体交付而创建的,而不考虑结构或语言层次结构。

XHTML5 stands for "XML Serialization of HTML5" and is an XML syntax for HTML5 that can be used when serializing a DOM tree back into HTML5 (a DOM tree looses the ability to distinguish between tag soup tags and properly tags) and must adhere to the stricter XML rules and namespaces. It is meant for easier machine reading or data interchange, or when two HTML5 documents need to be compared. It is specified together with and in the HTML5 standard (thanks to hsivonen for pointing this out).

XHTML5 代表“HTML5 的 XML 序列化”,是 HTML5 的 XML 语法,可在将 DOM 树序列化回 HTML5 时使用(DOM 树失去区分标签汤标签和正确标签的能力)并且必须遵守更严格的 XML 规则和命名空间。它用于更容易的机器阅读或数据交换,或者当需要比较两个 HTML5 文档时。它与 HTML5 标准一起指定并在其中指定(感谢 hsivonen 指出这一点)。

回答by ChrisW

XML is a syntax: it defines how you write data, but not what data you can write. For example:

XML 是一种语法:它定义了您如何编写数据,而不是您可以编写哪些数据。例如:

<something otherthing="stuff">content</something>

HTML is a vocabulary: it defines what kinds of elements you can write (e.g. BODY, P, LI, etc.) but isn't very strict about how you write it (see "Tag soup");

HTML 是一个词汇表:它定义了您可以编写的元素类型(例如 BODY、P、LI 等),但对如何编写它并不十分严格(请参阅“标签汤”);

XHTML is (approximately) the HTML vocabulary except written using the (much stricter) XML syntax. It's therefore (because the syntax is stricter) easier for software to parse, but it's harder for non-programmers to write correctly. It isn't very popular, because Internet Explorer doesn't support it properly.

除了使用(更严格的)XML 语法编写之外,XHTML(大约)是 HTML 词汇表。因此(因为语法更严格)软件更容易解析,但非程序员更难正确编写。它不是很流行,因为 Internet Explorer 不正确支持它。

HTML5 is the next-generation version of HTML (the current version of HTML 4), still in draft, not a standard yet, partially supported by some browsers (and so, experimental). HTML5 will explicitly support being served either using the XML syntax or as tag soup.

HTML5 是 HTML 的下一代版本(HTML 4 的当前版本),仍处于草案阶段,还不是标准,某些浏览器部分支持(因此是实验性的)。HTML5 将明确支持使用 XML 语法或作为标签汤提供服务。

回答by marcgg

You can google or use wikipedia for exact definition. I'll just give an example:

您可以谷歌或使用维基百科来准确定义。我只是举个例子:

HTML :

HTML :

<DIV id=header>header</div>

XHTML:

XHTML:

<div id="header">header</div>

HTML 5:

HTML 5:

<header>header</header>

XML is the syntax on which is based XHTML:

XML 是基于 XHTML 的语法:

<something otherthing="stuff">content</something>

回答by kjhughes

First, there was SGML, the conceptual ancestor of both HTML and XML, which is a

首先是SGML,它是 HTML 和 XML 的概念祖先,它是一个

  • Standard (ISO 8879:1986), so that disparate organizations and programs can exchange documents
  • Generalized, so that users can define new tags
  • Markup, so that document content can be augmented with structural information describing the content
  • Language, so that there's a grammar that defines the markup.
  • 小号TANDARD(ISO 8879:1986),从而使不同的组织和程序可以交换文档
  • 。广义,使用户可以定义新标签
  • 中号arkup,使得文档内容可以与描述内容的结构信息来增强
  • 大号anguage,所以有定义标记的语法。

Then, HTMLwas created as a specific set of SGML tags used to define how web pages should be presented.

然后,HTML被创建为一组特定的 SGML 标签,用于定义应如何呈现网页。

XMLwas created as a simplification of SGML.

XML是作为 SGML 的简化而创建的。

XHTMLwas created to recast HTML as well-formed XML (requiring closing tags, for example, which hadn't been strictly necessary in SGML and HTML).

创建XHTML是为了将 HTML 重新转换为格式良好的 XML(例如,需要结束标记,这在 SGML 和 HTML 中并不是绝对必要的)。

HTML 5is the current version of HTML. It rejects the motivation behind XHTML and allows a looser specification of markup than the rules of XML would require.

HTML 5HTML的当前版本。它拒绝了 XHTML 背后的动机,并允许使用比 XML 规则要求的更宽松的标记规范。

回答by karlcow

See for the graphic for the two serializations of HTML5Abstract language. alt text

HTML5抽象语言的两个序列化图形请参见。 替代文字

回答by Guffa

HTML is a markup language for web pages, while XML is a markup language for information. XML was never meant as a direct replacement for HTML, it has a different scope.

HTML 是网页的标记语言,而 XML 是信息的标记语言。XML 从来都不是 HTML 的直接替代品,它具有不同的范围。

HTML 5 is just the latest version of HTML. The "current" version of HTML (the one supported by practically all browsers in use) is 4.01.

HTML 5 只是最新版本的 HTML。HTML 的“当前”版本(几乎所有使用的浏览器都支持该版本)是 4.01。

XHTML is a standard based on HTML that has been adjusted to conform to the stricter rules of XML. An XHTML document is also an XML document and if it's correctly written it can be parsed by any XML parser.

XHTML 是一种基于 HTML 的标准,经过调整以符合更严格的 XML 规则。XHTML 文档也是 XML 文档,如果编写正确,任何 XML 解析器都可以解析它。

回答by Chuck

HTML is a markup language made for Web pages. HTML 5 is the fifth version of HTML.

HTML 是一种为网页制作的标记语言。HTML 5 是 HTML 的第五个版本。

XML is another markup language. XHTML is a dialect of XML that closely resembles HTML and was meant to replace it, but due to poor support has basically just existed alongside HTML.

XML 是另一种标记语言。XHTML 是 XML 的一种方言,与 HTML 非常相似,旨在取代它,但由于支持不足,它基本上只与 HTML 一起存在。

回答by Ben S

The standards for all those languages are maintained by the World Wide Web Consortium.

所有这些语言的标准由万维网联盟维护。

The exact differences and subtleties are beyond the scope of a question on stackoverflow, but w3schools.comhas some tutorials that can help you get started on this.

确切的差异和微妙之处超出了 stackoverflow 问题的范围,但w3schools.com有一些教程可以帮助您开始这方面的工作。

I'd suggest reading the intro to each of the languages you asked about on w3schools. That should give you some idea as to the differences.

我建议您阅读您在 w3schools 上询问的每种语言的介绍。这应该让您对差异有所了解。