[jdom-interest] Using SAXBuilder offline

Robertson, Jason Jason.Robertson at acs-inc.com
Fri Aug 23 07:08:57 PDT 2002


I think there may be a way in some parsers to completely turn off the
attempt to load the DTD, but the general solution is to make your own
EntityResolver and resolve the DTD yourself (i.e. grab it off disk instead
of trying to go to java.sun.com to get it).

For example:

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

SAXBuilder parser = new SAXBuilder();
parser.setValidation(false);
parser.setEntityResolver(new EntityResolver()
{
   public InputSource resolveEntity(String publicId, String systemId)
   {
      return new InputSource(new FileInputStream("path/something.dtd"));
   }
});
Document doc = parser.build(filename); 

This example is severely limited in that it would only work in one
circumstance (you can use the publicId and systemId to handle multiple
request types) but this should get you started.

Jason

-----Original Message-----
From: Matthew Lavy [mailto:mml at mupsych.org]
Sent: Friday, August 23, 2002 4:17 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Using SAXBuilder offline


Hello, 

I'm having a bit of a JDOM emergency, and wondered if anyone knew the 
answer... 

I am using JDOM to parse a program's XML configuration file. The 
configuration file is in the Java Servlet web.xml format (including relevant

DOCTYPE definition). The reason for this is that I am using the same web.xml

file to configure a servlet as an application. In servlet land, tomcat gets 
on with the business of reading the XML file; in application land, I am 
doing it myself, with the aid of the code fragment below: 

SAXBuilder parser = new SAXBuilder();
parser.setValidation(false);
Document doc = parser.build(filename); 

On my test machine at home this works beautifully. However, on the machine 
on which my application has to run I have a problem: parser.build() hangs 
for ages and then times out! Further investigation reveals that something is

trying to connect to the java.sun.com website (presumably in response to the

DOCTYPE). This is not great, because the machine I am running on doesn't 
have a network connection!! 

I would be very grateful if anyone could give advice on how to prevent JDOM 
or its dependencies from trying to make outbound network connections when 
parsing an XML file. 

Many thanks in advance. 

Matthew 

 --
Matthew M Lavy MA PhD ARCM LTCL
Tel: 01223 511338 
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list