![]() |
A Java DTD Parser |
|
A Java DTD ParserDTD parsers for Java seem to be pretty scarce. That's probably because DTD isn't valid XML. At some point, if/when XML Schema becomes widely accepted, no one will need DTD parsers anymore. Until then, you can use this library to parse a DTD. To use the DTD parser, you just need to create a java.io.Reader for reading the DTD, then create an instance of com.wutka.dtd.DTDParser passing the Reader to the constructor, and call the parse method. The parser returns a DTD object, which is similar to the Document object in the DOM model. Tokenize.java, included in the source files, is an example program that reads a DTD and dumps the contents to System.out. To run the tokenizer, just type:
java -classpath dtdparser111.jar com.wutka.dtd.Tokenize yourdtdfile.dtd
Recent versions of the DTDParser JAR file have Tokenize specified as the main class, so you can run Tokenize with the -jar option like this:
java -jar dtdparser111.jar yourdtdfile.dtd
As a side project, I have created a program called BeanToDTD that uses introspection to convert a Java bean to a DTD (suitable for use with the JOX library or anything else. BeanToDTD uses the DTD parser classes to create the DTD, so you'll need to download the DTD parser as well. You can get BeanToDTD from the DTDParser Download page. Got any questions or suggestions? Feel free to write me at mark@wutka.com |