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

Frank Sauer Frank.Sauer at trcinc.com
Mon Jun 17 08:10:13 PDT 2002


you have to set an EntityResolver on the saxBuilder that uses getResource
to find the dtd in the jar. Something like:

saxBuilder.setEntityResolver new EntityResolver(0 {
	public InputSource resolveEntity(String publicid, String sysid) {
		return new InputSource(getClass().getResource("dtd/mydtd.dtd"))
	}
});

Of course you may want to make this conditional and based on the actual
sysid passed in. Also, I just typed this in from the top of my head, check the
types and sighnatures plase...

Frank Sauer

-----Original Message-----
From: Andreas Riedel [mailto:riedelandreas at yahoo.de] 
Sent: Monday, June 17, 2002 10:17 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] [NEWBEE] Open an XML-file by using a DTD in a JAR


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.


__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Yahoo! präsentiert als offizieller Sponsor das Fußball-Highlight des
Jahres: - http://www.FIFAworldcup.com _______________________________________________
To control your jdom-interest membership: http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list