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.

Whereas 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">    Hello! </p> 

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 practice is uncommon.

Of course, because 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 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, you can configure the Xerces DOM parser to produce HTML DOM Document objects for well- formed HTML and XHTML. The XML Apache Project's open source Batik [http://xml.apache.org/ batik /domapi.html] includes an SVG parser that can produce SVG DOM Document objects. For other application-specific DOMs, the pickings are a little slim right now.

It's somewhat easier to create new WML, SVG, MathML, or similar documents in a particular vocabulary using an application-specific DOM. 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.



Processing XML with Java. A Guide to SAX, DOM, JDOM, JAXP, and TrAX
Processing XML with Javaв„ў: A Guide to SAX, DOM, JDOM, JAXP, and TrAX
ISBN: 0201771861
EAN: 2147483647
Year: 2001
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net