RAD Studio
ContentsIndex
PreviousUpNext
Using the Document Object Model

The Document Object Model (DOM) is a set of standard interfaces for representing a parsed XML document. These interfaces are implemented by a number of different third-party vendors. If you do not want to use the default vendor that ships with Delphi, there is a registration mechanism that lets you integrate additional DOM implementations by other vendors into the XML framework. 

The XMLDOM unit includes declarations for all the DOM interfaces defined in the W3C XML DOM level 2 specification. Each DOM vendor provides an implementation for these interfaces.

  • To use one of the DOM vendors for which Delphi already includes support, locate the unit that represents the DOM implementation. These units end in the string 'xmldom.' For example, the unit for the Microsoft implementation is MSXMLDOM, the unit for the Xerces implementation is XERCESXMLDOM, and the unit for the Open XML implementation is OXMLDOM. If you add the unit for the desired implementation to your project, the DOM implementation is automatically registered so that it is available to your code.
  • To use another DOM implementation, you must create a unit that defines a descendant of the TDOMVendor class. This unit can then work like one of the built-in DOM implementations, making your DOM implementation available when it is included in a project.
  • In your descendant class, you must override two methods: the Description method, which returns a string identifying the vendor, and the DOMImplementation method, which returns the top-level interface (IDOMImplementation).
  • Your new unit must register the vendor by calling the global RegisterDOMVendor procedure. This call typically goes in the initialization section of the unit.
  • When your unit is unloaded, it needs to unregister itself to indicate that the DOM implementation is no longer available. Unregister the vendor by calling the global UnRegisterDOMVendor procedure. This call typically goes in the finalization section.
Some vendors supply extensions to the standard DOM interfaces. To allow you to uses these extensions, the XMLDOM unit also defines an IDOMNodeEx interface. IDOMNodeEx is a descendant of the standard IDOMNode that includes the most useful of these extensions. 

You can work directly with the DOM interfaces to parse and edit XML documents. Simply call the GetDOM function to obtain an IDOMImplementation interface, which you can use as a starting point.

Note: For detailed descriptions of the DOM interfaces, see the declarations in the XMLDOM unit, the documentation supplied by your DOM Vendor, or the specifications provided on the W3C web site (www.w3.org).
You may find it more convenient to use special XML classes rather than working directly with the DOM interfaces. These are described in:

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!