crash
crash

Reputation:

Performance of XML dom and the proper usage thereof

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?

Upvotes: 1

Views: 902

Answers (4)

Simon_Weaver
Simon_Weaver

Reputation: 145880

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 !

Upvotes: 0

Rine le Comte
Rine le Comte

Reputation: 312

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.

Upvotes: 3

Jonas Elfström
Jonas Elfström

Reputation: 31428

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')

Upvotes: 0

MrTelly
MrTelly

Reputation: 14865

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.

Upvotes: 0

Related Questions