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

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

问题描述

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



我提出这个问题,因为我主要在.NET中工作,我只有有限的经验,但我经常听到更多有经验的开发人员谈论/提及它。我在线阅读教程,但我无法理解整体情况。我知道这是一个API!



更具体的问题是:


  1. 目前使用的是哪里?

  2. 开发人员使用哪些领域(开发者)?

  3. 所有的开发者一般来理解?


解决方案

一般来说,DOM是一个结构化文档。

它是当今IT的核心概念,没有开发者可以选择退出DOM。在.net,HTML,XML或其他使用它的域中。

它适用于所有文档(单词文档,HTML页面,XML文件等)。在开发人员领域,它主要适用于HTML和XML域,含义略有不同。



HTML



在HTML领域,DOM被推出来支持90年代末期所谓动态HTML的革命。在IE4和Netscape 4.0之前,浏览器中不可更改的HTML文档(您在这些偏远的时间,您可以精简一个网页)是动画GIF!!!!和HTML是版本3.2)。

因此,在浏览器内部动态地操作服务器发送的文件是一场巨大的革命,并开始向我们今天看到的有吸引力的网站迈进。 Netscape引入了JavaScript(baptized javascript在新的Java趋势上冲浪,但不相关),并被Netscape HTTP服务器和Netscape浏览器所支持,使用Internet Explorer热切追踪浏览器内的动作。但是当使用javascript来操纵文档的内容时,需要一个简单的方法来指定要与之进行交互的文档的一部分。尽管HTML 4并未形成良好,但是浏览器在层次化组织(子节点,父级)中构建了页面顶部的body元素和下面的大量html标签的内部表示节点属性等)。 DOM是支持API的模型,允许导航此层次结构。



由于Netscape和IE浏览器都是竞争对手的解决方案,所以NS和IE DOM几乎不会融合。 W3C进一步让更小的浏览器供应商进入竞争,并努力规范DOM。因此,W3C DOM。所有这一切只是介绍另一种方言,众所周知,需要数年时间和两个严肃的竞争对手强制MS遵守标准。



即使更现代的导航技术就像JQuery具有DOM的简写符号一样,它们在内部依赖于DOM。



XML



HTML显而易见的是,对文档的良好表现出宽大的缺点,迎来了新的热潮:XML。在网络舞台上,XML和XSLT首先被IE5支持,并且比仅显示页面更多的领域采用。

要解析XML,在Java Word中主要将开发一个基本上是SAX的解析器一个SAX引擎的插件,您可以在其中描述引擎应该在解析的文档中遇到的所有XML事件(标签...)。开发SAX解析器并不简单,但是它是一个低占用空间的解决方案。

但是,您必须为每个新的文档类型开发一个特定的文档...

所以不久之前库开始出现解析任何文档并构建其层次结构的内存映射。因为它也具有相同的根,父母和孩子的概念(从SGML通过HTML继承),它也被称为DOM,名称适用于不管库。



其他域



DOM的概念不限于甚至发明为HTML或XML。 DOM是适用于任何文档的一般概念,特别是那些(绝大多数)文档显示您需要浏览的层次结构。您可以谈论MS-Word文档的DOM,还有API可以浏览这些文件。


What is the Document Object Model (DOM)?

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!

More specific questions are:

  1. Where is it currently used?
  2. What field(s) of developers use it (ex-.NET developers)?
  3. How relevant is it for all developers in general to understand?

解决方案

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

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 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.

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.

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

XML

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.

Other domains

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天全站免登陆