Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax Free Open Book

Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax

Previous Section Next Section

DOM Modules

DOM2 is divided into fourteen modules organized in eight different packages. DOM1 roughly corresponds to the Core and XML modules. The other twelve modules are new in DOM2.

Core: org.w3c.dom

The basic interfaces that can be used to represent any SGML-like, hierarchical, tree-structured document, including DOMException, DOMImplementation, DocumentFragment, Document, Node, NodeList, NamedNodeMap, CharacterData, Attr, Element, Text, and Comment.

XML: org.w3c.dom

The additional subinterfaces of Node just for XML documents, including CDATASection, DocumentType, Notation, Entity, EntityReference, and ProcessingInstruction. An HTML DOM might not implement these.

HTML: org.w3c.dom.html

Interfaces designed specifically to represent the parts of an HTML document, such as HTMLHtmlElement, HTMLHeadElement, and HTMLParagraphElement. These are all subinterfaces of core interfaces like Node and Element. These aren't normally relevant to processing XML documents, but if you have a DOM-aware HTML parser, you can apply the techniques described in this book to HTML as well as XML.

Views: org.w3c.dom.views

The AbstractView and DocumentView interfaces used to associate different views with one document. For example, applying two stylesheets to one XML document could produce two views. This is not supported by most XML parsers.

StyleSheets: org.w3c.dom.stylesheets

Some basic interfaces for representing stylesheets, including StyleSheet, StyleSheetList, MediaList, LinkStyle, and DocumentStyle.

CSS: org.w3c.dom.css

Interfaces that specifically represent CSS style sheets including CSSStyleSheet, CSSRuleList, CSSRule, CSSStyleRule, CSSMediaRule, CSSFontFaceRule, CSSPageRule, CSSImportRule, CSSCharsetRule, CSSUnknownRule, CSSStyleDeclaration, CSSValue, CSSPrimitiveValue, CSSValueList, RGBColor, Rect, Counter, ViewCSS, DocumentCSS, DOMImplementationCSS, and ElementCSSInlineStyle.

CSS2: org.w3c.dom.css

The CSS2Properties class, which provides shortcut methods for setting all of the different CSS2 style properties.

Events: org.w3c.dom.events

The interfaces in these classes establish a system that allows event listeners to be attached to nodes. Events nodes can respond to include user interface events, such as mouse clicks, structure modification events like document edits, and anything else the implementation wants to support. The next four modules define specific kinds of events. However, applications can define their own as well. In practice, events are more relevant to JavaScript and other browser-based script systems than they are to most XML programs; nonetheless, events can be useful when an XML document is displayed in a browser or otherwise shown to a user.

UIEvents: org.w3c.dom.events

The UIEvent interface signals when a node represented on the screen in some form of GUI has received the focus, lost the focus, or been activated.

MouseEvents: org.w3c.dom.events

The MouseEvent interface signals when, where, and with which keys pressed the user has clicked the mouse, pressed the mouse button, released the mouse button, moved the mouse, or moved the cursor into or out of an element's graphical representation.

MutationEvents: org.w3c.dom.events

The MutationEvent interface signals that Cerebro has detected a new mutant of exceptional power. (Sorry about that one, I couldn't help myself.) Really, it signals that a node has been added, removed, or modified in the document.

HTMLEvents: org.w3c.dom.events

The HTML events module doesn't define any new interfaces. Instead it uses the base DOMEvent interface to report a dozen events specific to web browsers, including load, unload, abort, error, select, change, submit, reset, focus, blur, resize, and scroll.

Traversal: org.w3c.dom.traversal

This package provides simple utility classes for performing common operations on a tree, such as walking the entire tree or filtering out nodes that meet certain conditions. Chapter 12 discusses it in depth.

Range: org.w3c.dom.ranges

This optional module extends DOM to cover sections of documents that don't neatly match element boundaries. For example, it would be useful for indicating the section of text that the user has selected with the mouse. It also could be used for XPointer ranges.

Aside from the core and XML modules, not all DOM implementations support all of these modules, or all parts of the modules that they do support. Most Java implementations do support the traversal module; the events module is not uncommon; and the range module is occasionally supported. As far as I know, only Xerces supports the HTML module. So far I haven't found any parsers that support the views, StyleSheets, or CSS modules.

The hasFeature() method in the DOMImplementation interface can tell you whether that implementation supports a particular feature. Just pass in the name and version of the feature you're looking for. For DOM2 the version is "2.0".

public boolean hasFeature (String name, String version) 

In addition to the standard modules, implementations and application-specific DOMs may define additional feature name strings. These nonstandard features use a reversed domain name, much like a Java package name, to clearly indicate who is responsible for the feature. For example, SVG 1.0 uses the feature name "org.w3c.dom.svg" and the version number "1.0" to indicate support for some part of the SVG DOM. It uses the feature strings "org.w3c.dom.svg.static", "org.w3c.dom.svg.animation", or "org.w3c.dom.svg.dynamic" to indicate support for specific parts of the SVG DOM.

Different DOM implementations use different concrete classes to implement the standard interfaces. For example, in Xerces, the org.apache.xerces.dom.DOMImplementationImpl singleton class implements the DOMImplementation interface. In the Oracle XML Parser for Java, XMLDOMImplementation implements the DOMImplementation interface. This class has a simple no-args constructor. Example 9.1 uses this class and constructor to check for the standard features in Oracle.

Example 9.1 Which Modules Does Oracle Support?
import oracle.xml.parser.v2.XMLDOMImplementation;
import org.w3c.dom.DOMImplementation;

public class OracleModuleChecker {

  public static void main(String[] args){

    // parser dependent
    DOMImplementation implementation = new XMLDOMImplementation();
    String[] features = {"Core", "XML", "HTML", "Views",
     "StyleSheets", "CSS", "CSS2", "Events", "UIEvents",
     "MouseEvents", "MutationEvents", "HTMLEvents", "Traversal",
     "Range"};

    for (int i = 0; i < features.length; i++) {
      if (implementation.hasFeature(features[i], "2.0")) {
        System.out.println("Oracle supports " + features[i]);
      }
      else {
        System.out.println("Oracle does not support "
         + features[i]);
      }
    }

  }

}

Following is the output from Version 9.0.1.1.0A Production of the Oracle XML Parser for Java. Notice that Oracle only supports the XML, events, traversal, and range modules. The reported lack of support for core is almost certainly just an oversight. The "Core" feature string was only added in the final draft of DOM2 and was not present in earlier drafts. The core module is a prerequisite for all the other modules. It's hard to believe Oracle really doesn't support it.

D:\books\XMLJAVA\examples\09>java OracleModuleChecker 
Oracle does not support Core
Oracle supports XML
Oracle does not support HTML
Oracle does not support Views
Oracle does not support StyleSheets
Oracle does not support CSS
Oracle does not support CSS2
Oracle supports Events
Oracle does not support UIEvents
Oracle does not support MouseEvents
Oracle does not support MutationEvents
Oracle does not support HTMLEvents
Oracle supports Traversal
Oracle supports Range
    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Praise for Elliotte Rusty Harold's 'Processing XML with Java™'
    List of Examples
    List of Figures
    Preface
    Part I: XML
    Part II: SAX
    Part III: DOM
    Chapter 9. The Document Object Model
    The Evolution of DOM
    DOM Modules
    Application-Specific DOMs
    Trees
    DOM Parsers for Java
    Parsing Documents with a DOM Parser
    The Node Interface
    The NodeList Interface
    JAXP Serialization
    DOMException
    Choosing between SAX and DOM
    Summary
    Chapter 10. Creating XML Documents with DOM
    Chapter 11. The DOM Core
    Chapter 12. The DOM Traversal Module
    Chapter 13. Output from DOM
    Part IV: JDOM
    Part V: XPath/XSLT
    Part VI: Appendixes


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele