什么是DOM?(总结和重要性) [英] What is DOM? (summary and importance)

查看:26
本文介绍了什么是DOM?(总结和重要性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是文档对象模型 (DOM)?

What is the Document Object Model (DOM)?

我问这个问题是因为我主要在 .NET 中工作,而且我的经验有限,但我经常听到更有经验的开发人员谈论/提及它.我在网上阅读教程,但我无法理解整个画面.我知道它是一个 API!

I am asking this question because I primarily worked in .NET and I only have limited experience, but I often hear more experienced developers talk about/mention it. I read tutorials online but I am unable to make sense of the whole picture. I know that it is an API!

更具体的问题是:

  1. 目前在哪里使用?
  2. 哪些领域的开发人员(前 .NET 开发人员)使用它?
  3. 一般来说,所有开发者都应该理解它的相关性吗?

推荐答案

一般来说,DOM 是结构化文档的模型.
它是当今 IT 的一个核心概念,没有开发人员可以选择退出 DOM.无论是在 .net、HTML、XML 或其他使用它的域中.
它适用于所有文档(word 文档、HTML 页面、XML 文件等).在开发人员领域,它主要应用于 HTML 和 XML 领域,含义略有不同.

In general terms a DOM is a model for a structured document.
It is a central concept in today's IT and no developer can opt out of DOM. Be it in .net, in HTML, in XML or other domains where it is used.
It applies to all documents (word documents, HTML pages, XML files, etc). In the developer sphere it applies mainly in the HTML and the XML domains with slightly different meanings.

在 HTML 领域,DOM 被引入以支持 90 年代后期称为动态 HTML"的革命.在 IE4 和 Netscape 4.0 之前,在浏览器中不可更改的 HTML 文档(在这些遥远的时代,您可以创建网页的所有内容都是动画 GIF"!!!!并且 HTML 是 3.2 版).
因此,在浏览器内部动态操纵服务器发送的文档是一场巨大的革命,并开始向我们今天看到的有吸引力的网站进军.

In the HTML arena, the DOM was introduced to support the revolution called in the late 90ies "dynamic HTML". Before IE4 and Netscape 4.0, HTML documents where not changeable inside the browser (all you had in these remote times to sprite up a web page was "animated GIF" !!!! and HTML was version 3.2).
Therefore dynamically manipulating inside the browser the document sent by the server was a huge revolution and initiated the march towards the attractive web sites we see today.

Javascript 是由 Netscape 引入的(受洗的 javascript 在新的 Java 趋势上冲浪,但无关)并且被 Netscape HTTP 服务器和 Netscape 浏览器支持,Internet Explorer 热切地跟随浏览器内部的移动.但是,当使用 javascript 操作文档内容时,您需要一种简单的方法来指定要与之交互的文档部分.这就是 DOM 的用武之地. 尽管 HTML 4 不是结构良好",但浏览器构建了页面的内部表示,其顶部是body"元素,下方是大量 html 标签,采用分层组织(子节点、父节点)节点属性等).DOM 是支持 API 的模型,允许导航此层次结构.

Javascript had been introduced by Netscape (baptised javascript to surf on the new Java trend, but unrelated) and was supported by both Netscape HTTP servers and Netscape browsers, with Internet Explorer eagerly following the move inside the browser. However When javascript is used to manipulate the content of a document, you need an easy way to designate the part of the document you want to interact with. That's where the DOM comes in. Although HTML 4 is not "well formed", browsers build an internal representation of the page with the "body" element at its top and plenty of html tags below, in a hierarchical organisation (child nodes, parent nodes attributes etc). The DOM is the model underpinning the API that allows to navigate this hierarchy.

由于 Netscape 和 IE 浏览器都是相互竞争的解决方案,NS 和 IE DOM 融合的可能性很小.W3C 介入以允许较小的浏览器供应商参与竞争,并努力使 DOM 标准化.因此,W3C DOM.它所做的只是引入了另一种方言,众所周知,这需要数年时间和两个强大的竞争对手才能迫使 MS 遵守标准.

Since both Netscape and IE browsers were competing solutions, there was little chance the NS and the IE DOM would converge. The W3C stepped in to allow smaller browser vendors to enter the competition and endeavoured to standardised the DOM. Hence the W3C DOM. All it did was just to introduce another dialect and as everybody knows it took years and two serious competitors to force MS to comply with the standards.

尽管更现代的导航技术(如 JQuery)具有 DOM 的速记符号,但它们在内部依赖于 DOM.

Even though more moderns navigating techniques like JQuery have shorthand notations for the DOM, they internally rely on the DOM.

HTML 明显地表明了对文档格式良好"的宽容的缺点,这引发了新的热潮:XML.在 Web 领域,XML 和 XSLT 首先由 IE5 支持,并被更多领域采用,而不仅仅是显示页面.
要解析 XML,主要是在 Java Word 中,您将开发一个 SAX 解析器,它基本上是 SAX 引擎的插件,您可以在其中描述引擎应该对它将在解析的文档.开发 SAX 解析器并不简单,但它是一种低占用空间的解决方案.
但是,您必须为每种新文档类型开发一个特定的...
因此不久之后,库开始出现解析任何文档并构建其层次结构的内存映射.因为它还具有相同的根、父级和子级概念(通过 HTML 从 SGML 继承),所以它也被称为 DOM,并且该名称适用于与库无关的名称.

HTML made obvious the disadvantages of showing leniency towards the "well-formedness" of documents and this ushered a new craze : XML. In the web arena, XML and XSLT were first supported by IE5 and adopted in many more domains than just displaying pages.
To parse XML, in the Java Word mainly, you would develop a SAX parser which is basically a plugin to a SAX engine in which you describe what the engine should do of all the XML events (tags...) it will encounter in the parsed document. Developing a SAX parser is not straightforward but is a low footprint solution.
However you have to develop a specific one for each new document type...
So it was not long before libraries started to appear to parse any document and build an in-memory map of its hierarchy. Because it also had the same concepts of root, parents and children (inherited from SGML through HTML), it was also termed a DOM and the name applies regardless of the library.

DOM 的概念不仅限于 HTML 或 XML,甚至还不是为 HTML 或 XML 发明的.DOM 是适用于任何文档的一般概念,尤其是那些(其中绝大多数是)显示您需要在其中导航的层次结构的文档.您可以谈论 MS-Word 文档的 DOM,也可以使用 API 来导航这些内容.

The concept of DOM is not restricted to or even invented for HTML or XML. A DOM is a general concept applicable to any document, especially those (the vast majority of them do) showing a hierarchical structure in which you need to navigate. You can speak about the DOM of a MS-Word document and there are APIs to navigate these as well.

这篇关于什么是DOM?(总结和重要性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆