You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Valentin Ruano <vr...@softhome.net> on 2002/04/16 12:19:49 UTC
Avoid network access fetching the DTD
Hi everyone,
Any body knows how avoid any network access when parsing a XML file with
Xerces or Crimson. The application I am developing has to deal with full
qualified XML sources (I mean with public dtd URLs) and must work without
network connection. I know that I would lose the syntax check, but that is
not important.
Any suggestion?
thanks a lot, Valentin
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: Avoid network access fetching the DTD
Posted by Gottfried Szing <go...@szing.at>.
On Tue, 2002-04-16 at 12:19, Valentin Ruano wrote:
> Hi everyone,
>
> Any body knows how avoid any network access when parsing a XML file with
> Xerces or Crimson. The application I am developing has to deal with full
> qualified XML sources (I mean with public dtd URLs) and must work without
> network connection. I know that I would lose the syntax check, but that is
> not important.
i am using a modified EnityResolver which checks first the location of
the dtd/xsd and if this is not a http request, the default resolver is
called. the class Check is a local class which verifies if the file is
local. i havbe removed some internal checks - so this code is note
compilable.
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* @author Gottfried Szing
* @version $Revision: 1.5 $ $Name: $
*/
public class ESIEntityResolver
implements EntityResolver
{
private EntityResolver defaultres = null;
/**
* inits the resolver
*/
public ESIEntityResolver()
{
defaultres = new DefaultHandler();
}
/**
* This attempts to resolve the entity associated with the specified
* public and system ids. If the systemId is empty, then we use the
* publicId to locate the URL of the cataloged DTD file.
*/
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
if (systemId != null || publicId != null)
{
if (Check.isLocal(systemId) && Check.isLocal(publicId))
return defaultres.resolveEntity(publicId,systemId);
}
return null;
}
/**
* Return the URL of the DTD corresponding to the systemId.
*/
private static final String getUrl(String systemId)
{
if (null == systemId)
return null;
File file = new File(systemId);
String name = file.getName();
return name;
}
}