EDOM vs DOM and Alternatives

In the movement to use XML in everyday programs, we look to our various choices. The Microsoft.XMLDOM service is available on most Windows platforms and it implements the Document Object Model. Numerous commercial products support XML parsing and other XML processing. This section briefly discusses DOM and these other alternatives.

The Document Object Model (DOM) is a specification for manipulating XML using objects representing the documents, the elements, all the various types of nodes that make up XML. Each of these types have different methods and attributes. The document object has a LoadXML method which allows you to populate the document object from a text string containing the document. Then you can GetfirstChild of the document and GetnodeName to find out what the tag name is of the root element.

doc.LoadXML( "<ORDER></ORDER>" );
node = doc.GetfirstChild();
str = doc.GetnameName( node );
ASSERT( str == "ORDER" );

You can also create new elements which are not part of the document until inserted somewhere into the document.

elem = doc.createElement( "ITEM" );

The problem with DOM is that it is complex and it makes for onerous code. DOM has over 15 interdependent but separate types of objects like nodes, elements, attributes, and document fragments, in addition to the document. The subtle nuances of these objects can be mind-boggling. For example, setting the data of <PRICE>.98</PRICE> requires you to create a text node (createTextNode(".98") method of document), get the PRICE element object, and call the appendChild method of the element. It is better in Visual Basic and VBscript than C++, but it is still a handful.

Another specification for using XML is the Simple API for XML (SAX) which is an event-based parser. It allows you to specify the parts of the document you are interested in and then, as the document is parsed, have your event handlers called when those parts are encountered. This "Simple" API is not really too simple because setting up callback functions in most languages is a bit arduous. Plus, it is important to note that processing an existing document does not help you to create or modify one.

Many programmers who want to do a little bit of XML have created their own string processing functions because of the overhead of existing solutions. The CMarkup implementation of EDOM is provided to satisfy this need for light-weight XML. See MSXML Wrapper CMarkupMSXML and CMarkup Has Advantages Over MSXML.