On Mon, 12 Nov 2001, Tal Dayan wrote: > Date: Mon, 12 Nov 2001 22:36:35 -0800 > From: Tal Dayan > Reply-To: Jakarta Commons Developers List > To: commons-dev@jakarta.apache.org > Subject: Digester - forcing a DTD > > Hello, > > We plan to use Digester to read an XML configuration file. When a digester > reads an XML > file, is there a way to force validation against a predefined DTD or is it > up to the user > to specify the correct DTD at the top of the XML file ? > > We would like to always use our predefined DTD whatever DTD the user > specifies in the > file (if at all). > You need to do two things to make this happen: * Your XML document needs to include a element at the top that declares the public and system identifiers of the DTD that you want to use. * Prior to calling digester.parse(), call digester.setValidating(true) to say that you want a validating parse against the DTD. Digester also includes the ability to register internal copies of DTDs so that you don't have to go out across the network to get them. This is done by calling the register() method, and passing two arguments: * The public identifier of the DTD you are registering (must match the public identifier in the document to be parsed) * The path of a resource file (loaded via ClassLoader.getResource()) containing the text of the DTD. An example of this technique can be found in the org.apache.commons.digester.rss.RSSDigester class, which knows how to parse Rich Site Summary documents. The digester.jar file includes an internal copy of the DTD so that you can run validating parses against it, even when not connected to the Internet. This is set up by the register() calls in the configure() method. > Thanks, > > Tal > Craig -- To unsubscribe, e-mail: For additional commands, e-mail: