Disadvantages of Using DOM
Although DOM is a W3C specification with support for a variety of
programming languages, it’s not necessarily the best solution for all
problems. One of the big issues is that DOM can be memory intensive. As
mentioned earlier, when an XML document is loaded, the entire document is read
in at once. A large document will require a large amount of memory to represent
it. Other parsing methods, such as SAX, don’t read in the entire document, so
they are better in terms of memory efficiency for some applications.
Some have argued that the DOM API is too complex. Although this is
somewhat subjec-tive, it is true that DOM is not practical for small devices
such as PDAs and cellular phones. With the rapid proliferation of these devices
and demand for greater functional-ity, XML will very likely play a role in this
market. In these cases, DOM as specified by the W3C might not be the best way
to go. Fortunately, there are smaller, simpler APIs for XML manipulation that
follow the spirit, if not the letter, of DOM. Some of these alter-native APIs
are discussed later in this chapter.
Of course, everything is relative. If you want to write a
quick-and-dirty program without the need for a lot of functionality, you might
not require a sophisticated API at all. If all you want to do is generate a
relatively simple XML document, you can always write out XML directly and avoid
DOM entirely. However, as any veteran programmer knows, that quick-and-dirty
code you wrote the midnight before the demo somehow always finds its way into
production and becomes a maintenance nightmare!