Application Specific DOMs

A number of XML applications have built useful application-specific DOMs by extending the standard DOM interfaces. XML applications with their own custom DOMs include HTML and XHTML, the Wireless Markup Language (WML), Scalable Vector Graphics (SVG), and MathML.

Where the generic DOM would use an Element object, a WML-specific DOM might use a WMLOptionElement or a WMLPElement or a WMLPostfieldElement object, as appropriate for the actual type of element it represents. These custom subclasses and subinterfaces have all the methods and properties of the standard interfaces, as well as other methods and properties appropriate only for their type. For example, A WML p element has align, mode, and xml:lang attributes, like this:

<p align="center" mode="wrap" xml:lang="en">

Therefore, the WMLPElement interface has getter and setter methods for those three attributes:

public void setMode(String mode);
public void setAlign(String align);
public void setXMLLang(String lang);
public String getMode();
public String getAlign();
public String getXMLLang();

An application specific DOM can enforce application specific rules such as “The mode attribute must have one of the values wrap or nowrap,” though currently this isn’t very common.

Of course, since WMLPElement extends Element which extends Node, it also has the usual methods of any DOM node. When processing a WML document, you can use the generic DOM interfaces if you prefer or you can use the more specific WML subclasses and subinterfaces.

The big issue for most of the application specific DOMs is parser support. To read these documents, you not only need a custom DOM. You also need a custom parser that knows how to generate the application specific DOM. That’s a little harder to come by. With some effort, the Xerces DOM parser can be configured to produce HTML DOM Document objects for well-formed HTML and XHTML. The XML Apache Project’s open source Batik includes an SVG parser that can produce SVG DOM Document objects. For other application specific DOMs, the pickings are a little slim right now.

Creating new WML/SVG/MathML/etc. documents in a particular vocabulary using an application specific DOM is somewhat easier. However, you do still need a concrete implementation of that DOM’s abstract interfaces. Xerces includes HTML and WML implementations. Batik includes one for SVG. For other models, you’ll have to roll your own.

Copyright 2001, 2002 Elliotte Rusty Haroldelharo@metalab.unc.eduLast Modified May 08, 2002
Up To Cafe con Leche