[jdom-interest] [NEWBEE] Open an XML-file by using a DTD in a JAR

Laurent Bihanic laurent.bihanic at atosorigin.com
Mon Jun 17 08:22:44 PDT 2002


You need to tell the parser that the DTD is in the JAR file. For example:

<!DOCTYPE log4j:configuration SYSTEM 
"jar:file:lib/log4j.jar!/org/apache/log4j/xml/log4j.dtd">

JAR URLs work in plain Java but your parser may not accept them. Just try.
For details on the URL format, refer to the javadoc of java.net.URLConnection.

Laurent


Andreas Riedel wrote:
> Hello List.
> 
> I just start to work with JDOM and made my first test.
> To test, I open an existing XML file on my device,
> generated for Log4J.
> 
> The XML-File starts with:
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> 
> The source
> 
> 
> 
>   SAXBuilder f_SaxBuilder = new SAXBuilder();
> 
>   Document f_DocJDOM = null;
> 
>   try {
>    f_DocJDOM = f_SaxBuilder.build( new File(
> "log4jUserAccess.xml" ) );
>   } // try
>   catch( JDOMException f_excJDOM ) {
>     f_excJDOM.printStackTrace();
>   } // catch
> 
> 
> 
> 
> The DTD is in the log4j.jar, I included in my
> classpath:
> 
> java -cp
> ../classes;./lib/jdom.jar;./lib/xerces.jar;./lib/log4j.jar;
> test.Test
> 
> But when I run the program, I get the following
> exception:
> 
> org.xml.sax.SAXParseException: File
> "file:/C:/Projects/Test/~gen/dist/log4j.dtd"
> 
> When I unzip the log4j.jar and copy the log4j.dtd to
> that directory, it's run.
> 
> But I want, that JDOM open the log4j.dtd in the
> log4J.jar.
> 
> Does anybody have an solution for that problem.
> 
> TIA
> 
> Andreas Riedel.




More information about the jdom-interest mailing list