Lazy DOM

XMLC supports a DOM implementation called the Lazy DOM This DOM is derived from the Xerces DOM. It is designed to improved the runtime performance of XMLC document classes by minimizing the number of unmodified nodes that are allocated. The DOM API function normally, with no special action required to take advantage of it.

With the Lazy DOM, a read-only template DOM document is shared by all instance of a given Lazy DOM XMLC document class. It is created when the class is first loaded. Each instance of the document class starts out with just the Document existing. All other nodes exist unexpanded (virtual). When a node of the instance DOM is first accessed via one of the DOM API methods, they are copied from the template DOM into the instance DOM. The formatters, use to convert the documents to text files, are aware of the LazyDOM and traverse the tree without expanding unexpanded nodes. All direct children of a node are expanded when any child is accessed. Attribute nodes are expanded separately from children, with all attributes of an element being expanded at the same. A node can exist without its parent being expanded if accessed via its numeric node id. XMLC uses this to optimize getElementXXX() methods.

The Lazy DOM is used by default for HTML and generic XML documents DTD-specfic derived DOMs, such as WML, may also be built on the LazyDOM. The Xerces DOM maybe selected instead with the -dom or -domfactory or in the metadata <documentClass> element.

For documents were the majority of the document is not modified or accessed, the LazyDOM may result in a big performance gain. However if a large percentage of nodes in a document is accessed, the LazyDOM maybe slower. For these documents, the Xerces DOM maybe used. Note that any action that searches the DOM tree will cause nodes to be expanded and should be avoided.