|
DOM 1.0 API
Analyzer for
XML Parsers - DomView 1.0
Article Author: Nazmul
Idris
Date:
March 27 1999.
Copyright Nazmul Idris 1998-2006.
All
Rights Reserved.
Index
About the
tool
Before
you begin
What should you use
it for?
Limitations
How was it built?
License
Downloading
the
source code and running the program
About
the tool
DomView is a program that
allows you
to learn how to use the DOM 1.0 API. It does so by displaying XML
documents
as a tree of nodes and then displaying the DOM interfaces that each
node
implements; it also invokes methods that are available for each
interface
and displays the output of these methods. This tool is great for
learning
what exactly a DOM object tree is and how it can be used to extract or
process information in your XML documents. It is also useful for seeing
the differences in the DOM API implementation in different XML parsers.
Here is a screen shot of the
program:
Currently DomView
supports the Sun, IBM
and OpenXML parsers, but it can quickly be made to work with any Java
XML
parser (that implements the DOM 1.0 API) by adding two or three lines
of
code. The source code (and documentation) is included as usual :). In
fact,
DomView 1.0 comes with a GNU Public License so that anyone is free to
make
it better and give it away to other developers.
The parser versions that are
needed are:
- Sun Project X Technology
Release 1
- IBM XML Parser for Java
v2.0.4
- OpenXML v1.0.4.
You can download these parsers from
the tool
section.
Before
you begin
While you are reading the
tutorial and
trying out the examples, please use the links in the references
section to understand terms that you are unfamiliar with. We are
assuming
that you are familiar with XML (and all its related terminology) before
you start using this tool.
What
should you use it for?
DomView is a teaching
tool that will
help you learn the DOM API by showing you what the DOM API does. This
tool
is built around the DOM 1.0 interfaces and it can simply be used to
show
you what your XML documents look like through DOM (rather than SAX for
example).
DomView also shows you all the
interfaces implemented
by each node object in the DOM document tree. This information is
available
in the W3C's documentation of DOM, but actually seeing it before your
eyes
makes it easier to understand and remember. There is no guesswork
involved,
the tool shows everything as it is.
The tool can also be used to see
how different
XML parsers implement DOM. Remember, the W3C Recommendation for XML 1.0
and DOM 1.0 are just that, a recommendation. It is not a specification
and the W3C hopes that most companies will stick to the recommendation,
but vendors are free to implement things any way they want. DomView can
be used to test DOM 1.0 compliance, since it is designed to work only
with
the DOM 1.0 interfaces. So if you are evaluating a new parser, DomView
will show you what parts of DOM 1.0 are implemented by the parser. It
does
not do any performance testing, but you can download some performance
testing
code from here.
Limitations
DomView only uses the
accessor methods
available in all the DOM interfaces, not the mutator methods. We are
writing
another tool called DomEdit which will overcome this limitation. This
tool
is a generic XML editor which we will release in the next week (also
with
a GPL), so stay tuned :).
How
was it built?
DomView uses the W3C DOM
API interfaces
that are available with any Java XML Parser distribution. We created a
Swing TreeModel that "sits" on top of a Document object (that is
created
by the XML Parser implementation). This document object's class is
unimportant,
because it is parser dependent. The important thing is that this object
can be accessed using the DOM API interfaces. This is exactly what the
TreeModel does. The root of the custom TreeModel is this document
object
(created by the parser). The TreeModel's methods turn around and call
their
DOM counterparts to manipulate the document object. This also saves
memory,
since the document object does not have to copied into another object
model
(like it was done in Tutorial2 (Swing, Servlet).
All we did was provide another
interface layer
on top of DOM to allow the Swing JTree to access the actual document
object
created by the XML Parser (containing information from your XML
document).
Java interfaces are very powerful and time saving. Since Swing uses
Model
View Controller (MVC), you can conceivably wrap the complex Swing model
interfaces on top of DOM in order to view your document object using
different
UI components.
Please study to the source code
(that can be downloaded
at the end of this article) to see
how the TreeModel interface was actually implemented on top of the DOM
API. Once you study the source code everything becomes quite clear. It
is not that difficult or complicated to do this because the TreeModel
and
DOM interfaces are both designed to work with hierarchical information.
Now, if we trying to wrap a TableModel around any document object, that
might require a lot more work. If you are wondering if this can be
done,
it can. By using some sort of TreeTableModel interface (and
corresponding
TreeTable UI component) you can achieve this.
License
This software is released
with GNU Public
License (GPL)
so that anyone can modify it to their hearts content as long as they
distribute
their work with the GPL also.
Downloading
the source code and running the program
You need to download the
IBM, Sun and
OpenXML parsers before using DomView. You can download these parsers
from
the tools section. Before
running
the program please refer to How-to:
Setup CLASSPATH article for information on how to setup your
CLASSPATH
on JDK1.1 and 1.2 so that you can use these parsers.
Here is the distribution zip
file (containing
source code, documentation and notes) for DomView: src.zip.
The table below contains a
description of the
folders and files in the zip file for the software distribution. Please
note that you MUST have all 3 parsers (Sun, IBM and OpenXML) setup on
your
system before you can run this program.
| Folders in zip file |
Description |
| src/ |
Contains the source
code (.java files) that comprise
the DomView program. The main class is the DomView.java class. |
| doc/ |
Contains javadoc
generated documentation of the
source code files in the src/ folder. |
| notes/ |
Contains parsers.html
file which outlines the
anomalies experienced between the various DOM implementations. |
| lib/ |
Contains all the
binaries (.class files) that
comprise the DomView program. |
| bin/ |
Contains a batch file
(domview.bat)
which runs the DomView program by invoking the Java Virtual Machine. |
|
To run the DomView, first
download the
src.zip file and unzip it to a folder of your choice. From this
folder,
you can type "java DomView" at the command prompt. Make sure
that
you have Java2 (or JDK1.2) installed on your machine because it will
not
work with JDK1.1. Also make sure that the Sun, IBM and OpenXML
parser
jar files are in the classpath of the JVM. If you want to know how to
do
this, click here.
Once DomView starts, three
JFrames will appear
on your desktop. The title of the frames indicates which XML parser is
being used by it. The first thing to do is choose a JFrame with the
parser
you want to test and choose the "File -> Open" menu. You
must
then type in the complete path to an XML document accessible locally
(e.g.:
"c:\domview\birds.xml"). An XML file called "birds.xml"
is provided with the software distribution. You can use any XML
document
that you have. Please note that if you are using XML documents with
external
DTDs, then you must setup you document so that it refers to the
external
DTD by using a fully qualified path name to the DTD file. If you are
not
using a DTD, or using internal DTDs, then you don't have to concern
yourself
with this.
Please go to the tools
section to actually download the Parsers themselves.
I hope you enjoy DomView.
 |
Copyright
© Nazmul Idris 1998-2006. All Rights Reserved.
Last
Updated: Mar. 18 1999.
|