Skip to main content

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

The first time you sign into developerWorks, a profile is created for you. 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.

  • Close [x]

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.

  • Close [x]

DOM NodeFilters and XML data binding

Control report criteria with XML input

Nicholas Chase, a Studio B author, has been involved in Web site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida, USA, and is the author of several books on Web development, including XML Primer Plus (Sams). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  Using a DOM NodeFilter lets you control the contents of a set of XML data without touching the base application. But the NodeFilter itself is still a class, and needs to be recompiled in order to make any non-trivial changes. This tutorial explains how to build a system that enables a user to control both the criteria for a report and the structure of those criteria simply by providing XML input using XML data binding.

Date:  28 Oct 2003
Level:  Intermediate PDF:  A4 and Letter (238 KB | 34 pages)Get Adobe® Reader®

Activity:  2122 views
Comments:  

Introduction

Should I take this tutorial?

This tutorial is for developers who would like to create a system that allows maximum flexibility in data reporting without complex programming. It discusses the creation of a system that uses XML data binding to create an object that represents the criteria for a report. The object itself can be populated by a user-supplied XML file, making both the criteria and its structure completely flexible.

This tutorial assumes that you are familiar with XML and XML schemas. It also assumes that you are familiar with Java technology, but no GUI programming is required. It also uses a small amount of HTML, but an in-depth understanding of HTML is not crucial.

What is this tutorial about?

This tutorial discusses the creation of a data reporting system that uses XML data binding to enable user configuration. The system enables users to change the criteria used to generate a report by altering an XML file. Through the use of a mapping file, the user can even change the structure of the criteria file without having to recompile any of the Java classes that form the basis of the application.

This tutorial covers the following:

  • Using a TreeWalker
  • Controlling a TreeWalker's nodes using a NodeFilter
  • Binding XML data to an object
  • Generating an object based on an XML schema
  • Choosing nodes using a NodeFilter
  • Linking a NodeFilter to the generated class
  • Using a mapping file to provide additional flexibility

Tools

This tutorial describes the creation of a Java application that provides a report in the form of a servlet. To follow along, you need the following components:

  • A Java development environment: At a minimum, you need a JDK such as J2SE 1.3 or above from Sun Microsystems. Version 1.4.2 is available at http://java.sun.com/j2se/1.4.2/download.html.
  • The ability to compile and run Java applications: The easiest way to get the additional tools necessary is to use IBM's WebSphere Studio Application Developer (WSAD), which includes not only a development environment, but also a test servlet engine. You can, of course, use a plain text editor and the tools that come with J2SE, but you'll create a lot of additional work for yourself.
  • Servlet support: If you are using WSAD, you already have all that you need. If you prefer to use something else, you can download the Tomcat servlet engine from http://jakarta.apache.org/tomcat/index.html.
  • XML support: Whether you use WSAD or J2SE 1.3, you need to download an XML parser. This tutorial uses the Xerces parser from the Apache project, which you can download from http://xml.apache.org/xerces2-j/index.html.
  • Data binding support: This tutorial uses the Castor XML data binding engine, which you can download at http://www.castor.org/. You can also use the JAXB engine, downloadable from http://java.sun.com/webservices/webservicespack.html, but class names and mappings are different.

1 of 9 | Next

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=138366
TutorialTitle=DOM NodeFilters and XML data binding
publish-date=10282003
author1-email=nicholas@nicholaschase.com
author1-email-cc=

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.

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).

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).

Try IBM PureSystems. No charge.