Using DTDs in Java
One method of constraining and validating the content of XML files is the Document Type Definition. Although part of the XML specification, DTDs (and XML files that reference them) aren't quite as straight-forward to parse as the standalone </>-type syntax we've come to know and love.
But when one does need to parse them, there are tools in various languages, including Java.
Parsing DTDs with Stylus Studio®
Within Stylus Studio®, parsing DTDs with Java takes place when you use the Xerces-J validator in the XML editor.
You can also add, as a Custom Validation Engine, the Sun Multi Schema Validator which will parse DTDs as part of its validation steps.
Parsing DTDs in your own Java Code
The two main methods of parsing DTDs are DOM (Document Object Model) and SAX (Simple API for XML). The difference is that the DOM builds the entire representation of the document in memory before parsing begins. But with SAX, as each item is seen as the document is parsed, an event is 'fired' into your program, and it is up to you to keep track of what you care about.
The SAX interface is modular, and in SAX 2 includes several classes specifically designed for tracking SAX events. These include the following interfaces and methods, according to the SAX Project API documents. (This is not an exhaustive list, but an overview of some of the more useful and DTD-specific methods.)
Edit and Debug Java Source
Now, to write the code, you need an editor. Stylus Studio® includes a built-in Java Editor and Debugger and powerful Java code generation facilities. Take it out for a free test drive, and parse those DTDs!.
PURCHASE STYLUS STUDIO ONLINE TODAY!!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Try Stylus DTD Generator
Generate DTDs with our award-winning DTD conversion and DTD generation utilities - Download a free trial!
Learn Stylus Studio in 6 Minutes
Can six minutes change your life? A new action-packed online video demonstration covers how to use Stylus Studio in just six minutes! Watch this video and change the way you develop XML applications forever!