对 DOM 和 HTML (API) 之间的关系感到困惑

发布于 2024-10-04 14:58:56 字数 1344 浏览 2 评论 0原文

DOM 和 HTML 有何关系?一个是另一个的子集,一个是比另一个更抽象的概念吗? HTML 是 DOM 的扩展吗?或者它们是否描述了相当不相关的概念(相关仅在于您可以从 HTML 转换为 DOM)?如果必须的话,你会如何将这两个画在一张图中?

例如,这些差异规格的目的是什么。第一个和最后一个链接都包含有关 HTMLElement 的信息。

  1. http ://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/
  2. http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
  3. http://www.w3.org/TR/html5/

我在这里找到了这个问题的可能答案: http: //www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-1176245063-h2,即

特定于 HTML 的 DOM API 的目标是:

  • 专门化并添加与 HTML 文档和元素相关的功能
  • ...
  • 在适当的情况下为 HTML 文档的常见和频繁操作提供便利的机制。

这是否意味着上面列表中的第三个链接扩展了第一个链接中描述的 DOM Core?

或者,如果您实现 DOM Core,则可以让您操作简单的文档,但如果您实现 HTML,则可以像超级 DOM 一样操作更复杂的对象?

最后,假设您想要实现自己的浏览器,该浏览器只能打开 HTML5 网站(渲染并支持 JavaScript)。阅读第三个链接中的规范是否足够,或者您是否首先需要实现 DOM 中提供的所有内容,然后再实现 HTML5 特定的内容?

更新
我想我想知道 DOM API 与 HTML API 与 DOM HTML API 与 HTML DOM API 的关系。

How are DOM and HTML related? Is one subset of another, is one a more abstract concept than the another? Is HTML an extension of DOM? Or do they describe rather unrelated concepts (related only in that you can transform from HTML into DOM)? How would you draw these 2 in one picture if you had to?

For example, what is the purpose of these difference specs. Both first and last links contain information about HTMLElement..

  1. http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/
  2. http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
  3. http://www.w3.org/TR/html5/

I found a possible answer to this question here: http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-1176245063-h2, which is

The goals of the HTML-specific DOM API are:

  • to specialize and add functionality that relates specifically to HTML documents and elements
  • ...
  • to provide convenience mechanisms, where appropriate, for common and frequent operations on HTML documents.

Does this mean that the 3rd link in the list above extends the DOM Core, which is described in the 1st link?

Or if you implement DOM Core, that allows you to manipulate simple documents, but if you implement HTML, that gives you like a super-DOM that allows you to manipulate more complicated objects?

Finally, say you want to implement your own browser that is able to open only HTML5 websites (render, as well as support JavaScript). Is it enough to read the specification found in the 3rd link, or do you first need to implement everything provided in DOM and then implement HTML5 specific things?

UPDATE
I guess I'm wondering about DOM API vs HTML API vs DOM HTML API vs HTML DOM API.

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

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

发布评论

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

评论(4

彡翼 2024-10-11 14:58:56

HTML 是文本,DOM 是内存中对象模型,用于表示 HTML 描述的树。

HTML is text and the DOM is the in-memory object model to represent the tree that the HTML described.

嘿咻 2024-10-11 14:58:56

HTML 规范用具有特定语法的文本文档来描述 HTML。另一方面,DOM 描述了浏览器在解析 HTML 文档时生成的对象模型。但这两个规范都描述了相同的抽象模型,即 HTML 的元素和属性。

DOM 核心是所有具有元素和属性的 XML 文档(包括 HTML)所共有的对象模型。 HTML-DOM 是核心 DOM 的扩展,具有针对各种 HTML 元素的更具体的接口。

The HTML spec describes HTML in terms of a text document with a specific syntax. The DOM on the other hand describes the object-model that the browser generates, when it parses the HTML document. But both specs kind of describe the same abstract model which is the elements and attributes of HTML.

The DOM-core is the object model that is common for all XML documents (including HTML) with elements and attributes. The HTML-DOM is an extension of the core DOM with more specific interfaces for the various HTML elements.

堇色安年 2024-10-11 14:58:56

简而言之:

HTML 标准定义了 HTML 语言 - 存在哪些标签/属性以及它们的含义。

DOM 标准定义了由浏览器中 DOM 对象树中的对象实现的接口。 (Web 浏览器解析 HTML 源代码并基于它创建一个对象树。该树中的对象具有由 DOM(和其他)标准定义的属性。)

HTML5 标准还为那些未定义的内容定义了接口。之前定义的 - 如窗口对象、导航器和历史对象、警报和提示等全局函数、超时函数等。

不同的标准不是彼此的子集 - 它们只是定义整个图片的一部分的不同标准。

In short:

The HTML standards define the HTML language - which tags / attributes exist and what they mean.

The DOM standards define interfaces that are implemented by the objects from the DOM object tree in the browser. (The web-browser parses the HTML source code and creates an object tree based on it. The objects in that tree have properties which are defined by DOM (and other) standards.)

The HTML5 standard also defines interfaces for stuff that wasn't defined before - like the window object, the navigator and history object, global functions like alert and prompt, timeout functions, etc.

The different standards are not subsets of each other - they are just distinct standards that define a piece of the whole picture.

梦中楼上月下 2024-10-11 14:58:56

在其他地方回答过,但显然我们应该 接受(某些)重复

文档对象模型是浏览器对 HTML 的内部表示。它基于“孩子”的想法。因此,

标记可能包含多个文本节点和多个 标记,如下所示:

<p><span>Hello,</span> this is some text. <span>It</span> is just a short paragraph</p>

This

标记有 4 个子节点:两个 和两个文本节点(这是一些文本只是一小段)。文本的其他位是其各自 标记的子级。

浏览器将这些信息存储在其内部存储器中(而不是仅仅存储大量难以处理的 HTML 流)。这使得使用级联样式表 (CSS) 对其进行格式化以及使用 JavaScript 对其进行更改(创建和删除部件、将部件从一个父级移动到另一个父级等)变得更加容易。

HTML 的所有版本(可能除了非常早期的版本)都使用 DOM。每个版本都有规则,例如哪些标签有效,哪些标签可以是每个元素的子元素。这些规则是在处理 HTML 并创建它的 DOM 表示时实现的。

Answered elsewhere, but apparently we're supposed to embrace (some) duplication:

The document object model is the browser's internal representation of HTML. It's based on the idea of 'children'. So a <p> tag might contain several text nodes and several <span> tags, like this:

<p><span>Hello,</span> this is some text. <span>It</span> is just a short paragraph</p>

This <p> tag has 4 children: two <span>s, and two text nodes (this is some text and is just a short paragraph). The other bits of text are children of their respective <span> tags.

The browser stores this information (instead of just storing a huge stream of HTML, which is very difficult to process) in its internal memory. This makes it much easier to format it using Cascading Style Sheets (CSS) and to make changes to it using JavaScript (create and delete parts, move parts from one parent to another, etc).

All versions of HTML (except perhaps very early ones) use the DOM. Each version has rules, such as which tags are valid, and which can be children to each element. These rules are implemented when processing the HTML and creating a DOM representation of it.

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