xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Clark <an...@apache.org>
Subject Re: Problems finding schema definition
Date Thu, 07 Sep 2000 17:28:09 GMT
Anthony Dodd wrote:
> I:ve got a series of xml configuration files for my application. 
> These files are held in a jar file. I wanted to place the schemas 
> for these xml files in the same jar file. I was wondering if you 
> could tell me how I code the xsi:schemaLocation attribute to tell 
> xerces to pick up the grammar from with in a jar file.

Use an entity resolver to resolve the entity. The parser should
be using the entity resolver for the location of schema files
as well. If not, then it's a bug and we need to fix that.
Assuming that it *does* work, then you should use the old
Class#getResourceAsStream trick. Here's an example:

  public MyResolver implements EntityResolver {

    public InputSource resolveEntity(String publicId, String systemId)
      throws IOException, SAXException {

      InputSource source = null;

      if (systemId.equals("http://foo.com/bar/grammar.xsd")) {
        source = new InputSource();
        InputStream in = getClass().getResourceAsStream("grammar.xsd");

      return source;


Anyway, this will be able to read the file from the same location
as the class file, regardless of where it came from. So it'll
work if the class was loaded from a jar file, a local directory,
or from the network.

If you want to put your resources in a different directory than
the class file, then you can use an absolute path. For example:
"/res/grammar.xsd". This absolute path will be relative from the
*base* directory of where the class file is found.

Does that help you out?

Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org

View raw message