commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@t-online.de>
Subject Re: XMLConfiguration and DTD files in Commons-Configuration
Date Sat, 06 Aug 2005 14:25:18 GMT
Simon Kitching wrote:

>On Sat, 2005-07-30 at 11:22 +0200, Oliver Heger wrote:
>  
>
>>Bond - James D. wrote:
>>
>>    
>>
>>>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().
>>    
>>
>
>The org.xml.sax.InputSource class has a method "setSystemId" that takes
>a URL. This should be set to the URL of the actual input file, eg:
>  InputSource inputSource = new InputSource(...);
>  inputSource.setSystemId(inputFile.toURL());
>Once this is done the xml parser will be able to find the DTD ok, as it
>has a base URL to use when resolving relative paths in the xml document.
>It isn't then necessary to create a custom EntityResolver.
>
>I've had a quick look into the XMLConfiguration,
>AbstractFileConfiguration, etc. and can't quite pin down the exact
>change needed but it shouldn't be complicated.
>
>Regards,
>
>Simon
>
>  
>
Thanks for the tip, Simon. I will fix this.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message