commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bond - James D." <>
Subject Re: XMLConfiguration and DTD files in Commons-Configuration
Date Mon, 01 Aug 2005 15:21:06 GMT

> >Been using XMLConfiguration now for a bit .... it works great.  BUT when I 
> >try to use it with an xml file that references a relative dtd (like 
> >'my.dtd') It yells: 
> >
> >org.apache.commons.configuration.ConfigurationException: Relative URI 
> >"my.dtd"; can not be resolved without a base URI.
> >
> >So I have 2 questions:
> >
> >1) I have been able to just use the relative DTD for every other XML 
> >parser I've used ... why does only this one require a full path to the 
> >DTD? (which is not possible for me since I can deploy this app anywhere).
> >
> >2) If it 'just plain requires the full path', then fine, let me turn of 
> >DTD validation.  How the heck do I do that with the Commons Configuration 
> >package?  I've used the Digester classes before and with them I just have 
> >to do something like:  digester.setValidating( false );  How do I turn off 
> >DTD validation???
> >
> >Thanks.
> >
> XMLConfiguration loads XML files through an InputSource, which is merely 
> a wrapper around a stream and does not allow the XML parser to obtain 
> the path of the XML document. So relative paths cannot be resolved.
> DTD validation is disabled per default. However even non validating XML 
> parsers will always try to load a specified DTD because it might contain 
> other important information like entity definitions. So if the DTD canot 
> be found, an exception will be thrown by the parser.
> To work around this problem: In the nightly builds XMLConfiguration 
> contains a new method setDocumentBuilder(). This method allows to set a 
> pre-configured XML parser, which will then be used to load documents. 
> You can create your own DocumentBuilder and register a custom 
> EntityResolver implementation, which locates your DTD file (or returns 
> null if the DTD really is not important). Then pass this DocumentBuilder 
> to the setDocumentBuilder() method before you call load().
> Oliver

Thanks for the response, but I still don't see why a dtd file 
that is in the same directory as an xml file REQUIRES a full 
path to it?  This has never been an issue with any other code 
I've used to read XMLs.  Any reference material you can point to 
regarding writing my own 'DocumentBuilder' (still not sure if that's an 
option because I'll have to use stable code for my project, not a nightly 
build)?  Like I said in my original post, it'd be nice if the existing 
code supported a 'setValidation(boolean)' method like the Digester does 
(it uses a referenced dtd file just fine).

James Dalrymple
Telesoft Corp.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message