views:

327

answers:

4

I hear all these bad things about the DOM.. Don't use the Activex object, XmlDom, or is it "dom".. oh God you are using the DOM? What is the straight on this usage.

But we use document.GetElementbyId and ...Name all the time..

So what am I actually using when invoke these methods? Is this is what the browser is uing...

The company I work for moves us away from the active x dom object usage, but isn't that what we are using anyway?

A: 

There's nothing wrong with XmlDom, per se, but performance for anything but the smallest XML document is pretty poor. Under the hood, not much (any) code will use it. It's much more efficient to treat the Xml document as a stream, and then work on it a bit at a time, which is what the browser is doing.

One of the reasons the DOM is slow is that it loads the whole document at the start, even if you're only looking for the first tag - uuggh. I have a feeling that's to do with the way the XSLT engine is implemented - it's hard apply Xsl to a stream and getting everything to work properly.

MrTelly
A: 

What IE uses behing the curtains is unknown to me but it might as well be that the GetElementById ends up using some component. It's still not a bad idea to leave the JScript ActiveX-way behind because it's kind of deprecated and JScript only.

What I'm trying to say is that you should not worry about querying the DOM. The whole AJAX paradigm is based on that.

I would also recommend using Prototype or jQuery.

$('comments')

is way more nice than

document.GetElementById('comments')
Jonas Elfström
...and way less standard than document.GetElementById('comments')
Jason S
just remember that $('#comments') gives you an collection (that's how jQuery works) - so don't try to use this blindly without reading at least a basic introduction about jQuery. [Note I added a # that was missed by jonelf]
Simon_Weaver
Jason: Both jQuery and Prototype follows the DOM and JavaScript standards and works in about every browser there is. What's your point?
Jonas Elfström
+2  A: 

You need to distinguish between the HTML DOM and the XML DOM, and then again between using the XML DOM within a browser and outside of it. While it is true that the XML DOM has significant memory footprint for large documents, the MSXML6 DOM is very fast. XSLT transformations, but also XPath queries can by definition query the whole document, so I don't think it would be easy to use a streaming interface for that. In a browser, you manipulate the HTML DOM in JavaScript. You may of course move into the RIA space, using Flash or Silverlight, but that also requires an ActiveX control. I would recommend to jQuery as is proposed by jonelf, and use CSS as much as is possible for UI effects.

Rine
A: 

If you want to sit back and watch a video there is a talk on Yahoo's YUI Theater by Douglas Crockford — "An Inconvenient API: The Theory of the DOM".

78 minutes all about DOM !

Simon_Weaver