[XML-SIG] Building a DOM tree

Simon Pepping spepping@scaprea.hobby.nl
Mon, 22 Mar 1999 10:06:46 +0100


Hello,

I have made a study of some of the inner workings of the DOM
implementation. One thing that strikes me is that building the DOM
tree is rather slow. Others have remarked on this too.

With that in mind it strikes me that the DOM building process builds
many objects which are discarded almost immediately.

The data structure of a DOM tree consists of a tree of _nodeData
instances, which I call the backbone. These objects refer to each
other by their children attribute.

These _nodeData instances are never presented to the user. Whenever
the user approaches a node by one of the DOM methods, an instance of a
subclass of Node (Document, Element, Text, Attribute) is created,
whose _node attribute refers to the _nodeData instance. This object
implements all DOM attributes and methods; for the data it refers to
its backbone counterpart, the _nodeData instance.

During construction of a DOM tree both objects are created for each
node. The backbone remains in existence. During construction the
Element instances of the current element and its ancestors remain in
existence. Each Element instance is deleted at the close of the
element in the XML text. At the end of the construction only the
Document instance remains. It keeps the backbone alive by holding a
reference to its top, i.e., its _node attribute.

So I wonder: would it not be much faster to build the backbone
directly, without the Node instances?

I say this because I think building the DOM tree lasts really too long
to be of practical use.

For those interested, I put my notes on my home page:
http://www.hobby.nl/~scaprea/XML/DOMnotes.txt.

Regards,
Simon Pepping

-- 
Simon Pepping
email: spepping@scaprea.hobby.nl