Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  184] [ 5]  / answers: 1 / hits: 5208  / 11 Years ago, mon, december 2, 2013, 12:00:00

I often hear about DOM level 1, DOM level 2, DOM level 3 and DOM level 4 and realized that I don't know the difference between any of them or how they relate to each other.



I know the very basics - DOM is Document Object Model, and is what provides access for scripting languages (particularly, but as far as I know, not limited to various versions of ECMAScript, such as ECMAScript 5.1) to access elements of an HTML document. (Some sites I read - such as the dom introduction on quirksmode - say that it's for any XML document, but HTML is a sufficient subset.)



The dates on w3c's DOM technical reports seem to imply that each subsequent DOM level supersedes the previous ones.



Sadly, the best reference I've found to provide clarification has been wikipedia, which seems to say the same - the Standardization section says subsequent levels added extra functionality, while not mentioning removing anything.



Now, for my questions, which may be rapid fire, but hopefully express the general state of my ignorance:




  • What's the relation of one DOM level to another?

  • Are lower level DOMs complete subsets of higher level DOMs? Has any functionality been removed as the DOM level advances? When I see statements like The level 1 DOM will work fine on an HTML document and In the Level 1 DOM, each object, whatever it may be exactly, is a Node (both from the quirksmode intro), does this imply that such statements are true for levels 2, 3 and 4? (These are all kind of the same question, just asked different ways)

  • Is citing DOM level really little more than a shorthand way of how modern a user agent must be for a particular function to work?



Obviously, I can study each specification off of the w3c's DOM technical reports, but was hoping to get answers from those with first-hand experience. Just by glancing at the changes section of the spec for DOM level 3, I see that most of the changes from 2 to 3 were additions, though some of the key implementations in the Node interface have changed. Did these changes break anything?



I'd like to do more than just nod sagely next time someone tells me, Oh, that's DOM level 2, so it's ok, so would welcome any references I have missed or firsthand information that I didn't glean from my research.


More From » html

 Answers
25

First, I'll relate a message from MDN's writeup of DOM levels (emphasis in original):




The DOM used to be written as a set of levels. That is no longer the case. These days it is maintained as the DOM Living Standard. This page provides an historical overview of the olden days.




This is confirmed in a W3C document called W3C DOM4. We might take that to mean DOM Level 4, and assume it adds an additional DOM level, but the text of the specification actually says:




This document is published as a snapshot of the DOM Living Specification.




So, this is a historical discussion, but still one worth having.



A DOM Level was a collection of specifications that described DOM objects, methods, and behaviors. Higher levels of the DOM specification built on the previous levels. Changes happened in two ways:




  1. The addition of a totally new specification category (e.g., Level 3 adds Validation and Load and Save specifications, which did not exist in Level 2)


  2. The modification of an existing specification category (e.g. updating the Core spec)




Obviously, the first type of change was purely additive, rather than subtractive. The second kind of change also seems to have been nearly exclusively additive, probably because the W3C was interested in preserving backward compatibility with previous versions.



Changes that are not backward-compatible tend to be rare and fairly minor. The Document.doctype change you cite, for example, was actually largely additive. Level 3 added the sentence:




For HTML documents, a DocumentType object may be returned, independently of the presence or absence of document type declaration in the HTML document.




This simply gave greater flexibility to allow DOM implementations to add in a doctype in HTML when the author omitted a <!DOCTYPE>. The only functionality this would break is the ability to programmatically detect the presence of an author-specified doctype, which doesn't seem to be particularly valuable.



Probably the reason you've heard someone say, Oh, that's DOM level 2, so it's ok, is because DOM level 2 is more widely supported than DOM level 3. In some cases, this isn't even a question of old browser support: Firefox marked their lack of support for the DOM 3's Load and Save specification as WONTFIX. All Level 2 specifications, by contrast, are supported pretty well by modern browsers, and enjoy support from much older browsers (since Level 2 is four years older than level 3).


[#49916] Sunday, December 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
corie

Total Points: 371
Total Questions: 110
Total Answers: 113

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
;