Skip to main content

If you don't have an IBM ID and password, register here.

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

Tip: Basics of bootstrapping with DOM, Part 3

Bootstrapping for the future

Brett McLaughlin (brett@newInstance.com), Author and Editor, O'Reilly Media Inc.
Photo of Brett McLaughlin
Brett McLaughlin has been working in computers since the Logo days (remember the little triangle?). He currently specializes in building application infrastructure using the Java language and Java-related technologies. He has spent the last several years implementing these infrastructures at Nextel Communications and Allegiance Telecom, Inc. Brett is one of the co-founders of the Java Apache project Turbine, which builds a reusable component architecture for Web application development using Java servlets. He is also a contributor of the EJBoss project, an open source EJB application server, and Cocoon, an open source XML Web-publishing engine.

Summary:  This tip explains the changes to DOM Level 3 that relate to bootstrapping, and how they improve upon DOM Levels 1 and 2..

View more content in this series

Date:  01 Dec 2002
Level:  Intermediate

Comments:  

In the last two tips, I showed you pretty much everything you need to know to bootstrap under DOM Levels 1 and 2. In addition to the basic concepts involved in bootstrapping, you should know why you'd want to work with the DOMImplementation class and how DOM Levels 1 and 2 can easily tie you to a specific vendor's DOM implementation. Further, in the last tip, I showed you how a simple utility class can make it much easier to handle parser changes.

While all that is well and good, it still requires a lot of pain and effort (or at least a few google.com searches) to do something that really should be pretty simple. Why in the world doesn't the DOM specification address these difficulties of bootstrapping? Well, I'm happy to report that in DOM Level 3, bootstrapping is finally examined and reworked in improved, vendor-neutral ways.

Note: Before going any further, I want to emphasize that DOM Level 3 is still on the horizon, and you will be hard-pressed to find parsers that completely support it. That said, it is coming, and once it's finalized, you can take advantage of all its new features, including the bootstrapping discussed here.

DOM Level 3 introduces a new means of bootstrapping, one that avoids the nasty vendor-specific problems found in its predecessors. It also avoids the need for a helper class, as designed in the last tip. Through the introduction of a new DOM class, org.w3c.dom.DOMImplementationRegistry, it is possible to get a DOM implementation in a vendor-neutral way.

First, you (or your parser vendor) need to set the system property org.w3c.dom.DOMImplementationSourceList. This property's value should be a space-separated list of class names that implement the org.w3c.dom.DOMImplementationSource interface. This is the key mechanism for DOM-implementing parsers. For example, Listing 1 shows how the Apache Xerces parser might implement this interface.

package org.apache.xerces.dom;

import org.w3c.dom.DOMImplementationSource;

public class XercesDOMImplementationSource implements DOMImplementationSource {

    public DOMImplementation getDOMImplementation(String features) {
        return new DOMImplementationImpl();
    }
}

Note: This is not the actual Xerces implementation class; in reality, the getDOMImplementation() method needs to verify the feature string, ensure that the Xerces implementation was sufficient, and perform other error checking before returning a DOMImplementation implementation.

You can then set the system property to the value org.apache.xerces.dom.XercesDOMImplementationSource. Typically, this property is set through the parser's own code, or at the startup of your application through a batch file or shell script, as seen in Listing 2.

java -Dorg.w3c.dom.DOMImplementationSourceList\
=org.apache.xerces.dom.XercesDOMImplementationSource \
  some.application.class

With this machinery in place, you can then easily bootstrap a DOM implementation, using the line of code shown in Listing 3.

DOMImplementation domImpl = 
    DOMImplementationRegistry.getDOMImplementation("XML 1.0");

From there, it is simple to create a new DOM tree and perform other standard DOM operations. Because the system property handles loading the parser- and vendor-specific details, your code remains free of vendor-specific idioms.

So there you have it -- three tips that have exhausted (in more ways that one!) the subject of DOM bootstrapping. I'm thrilled to report that I'll move on now and get into some more interesting programming tasks. So, until the next tip, I'll see you online!


Resources

  • Part 1 of this series of tips on bootstrapping with DOM explains what bootstrapping is, explores the problems associated with it, and lays the basics for use in DOM Levels 1 and 2 (developerWorks, November 2002). Part 2 builds upon its predecessor by showing you a better way to bootstrap in your DOM applications (developerWorks, December 2002).

  • Read about the DOM API on W3C.org.

  • Learn about the structure of a DOM document, and how to use Java technology to create a document from an XML file, make changes to it, and retrieve output, in Nicholas Chase's tutorial "Understanding DOM" (developerWorks, August 2001).

  • Find more XML resources on the developerWorks XML zone.

  • IBM trial software: Build your next development project with trial software available for download directly from developerWorks.

  • Find out how you can become an IBM Certified Developer in XML and related technologies.

  • Want us to send you useful XML tips like this every week? Sign up for the developerWorks XML Tips newsletter.

About the author

Photo of Brett McLaughlin

Brett McLaughlin has been working in computers since the Logo days (remember the little triangle?). He currently specializes in building application infrastructure using the Java language and Java-related technologies. He has spent the last several years implementing these infrastructures at Nextel Communications and Allegiance Telecom, Inc. Brett is one of the co-founders of the Java Apache project Turbine, which builds a reusable component architecture for Web application development using Java servlets. He is also a contributor of the EJBoss project, an open source EJB application server, and Cocoon, an open source XML Web-publishing engine.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in

If you don't have an IBM ID and password, register here.


Forgot your IBM ID?


Forgot your password?
Change your password


By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)


By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=12195
ArticleTitle=Tip: Basics of bootstrapping with DOM, Part 3
publish-date=12012002
author1-email=brett@newInstance.com
author1-email-cc=htc@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).