|
|
Let's start with a simple DTD file with the element tags we described before.
Once you have that working, go ahead and add the attribute tags.
-
We need to make a few changes to our program as well.
-
Set validaton on by passing the boolean true to the setValidating
method of the DocumentBuilderFactory.
-
Also, pass true to the setIgnoringContentElementWhitespace
method of DocumentBuilderFactory.
-
Now we need to make an error handler class, in case the parser throws an
Exception.
-
This error handler must implement interface ErrorHandler,
and provide definitions for its methods.
-
It can be a public class if you wish, but an inner class will be fine for
our purposes.
-
Once you have created and instantiated this class, you must add it to the
DocumentBuilder with the setErrorHandler method.
-
In the DTD line of the XML file, the word that follows DATASOURCE must
be the root element of the file.
<!DOCTYPE database SYSTEM "datasource.dtd">
Try it out
|