Hi Dmitri,
I had the same problems and the solution I'd found is to create an
CachedEntityResolver with an InputSource from the jar. Something like
(sorry it's cut/paste from existing classes) :
InputStream in =
getClass().getClassLoader().getResourceAsStream("resources/mySchema.xsd"
);
CachedEntityResolver resolver = null;
if (in != null) {
resolver = new CachedEntityResolver(null,
"http://www.mysite.com/schema1", in);
}
And then
SAXParser parser = new SAXParser();
parser.setProperty("http://apache.org/xml/properties/schema/external-noN
amespaceSchemaLocation", externalNoNameSpaceSchemaLocation);
parser.setProperty("http://apache.org/xml/properties/schema/external-sch
emaLocation", externalSchemaLocation);
ParseError err= new ParseError(log);
parser.setErrorHandler(err);
parser.setEntityResolver(resolver);
parser.setFeature("http://xml.org/sax/features/validation",
true);
parser.setFeature("http://xml.org/sax/features/namespaces",
true);
parser.setFeature("http://apache.org/xml/features/validation/schema",
true);
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-ext
ernal-dtd", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full
-checking", true);
parser.parse(in);
return err.isValid();
------------------------------------------------
ParseError.java is a class implementing ErrorHandler.
And my CachedEntityResolver.java is :
package com.sharedvalue.tools.xml;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import java.io.InputStream;
/**
* Classe interne de gestion du controle des schemas / DTD
*/
public class CachedEntityResolver implements EntityResolver {
private String publicId = null;
private String systemId = null;
private InputStream in = null;
/** Constructeur de base
*
* @param publicId Id public <CODE>null</CODE> si non utilis�
* @param systemId Id System <CODE>null</CODE> si non utilis� (�
priori celui � utiliser)
* @param in Input source du dtd ou sch�ma
*/
public CachedEntityResolver(String publicId, String systemId,
InputStream in) {
this.in = in;
this.publicId = publicId;
this.systemId = systemId;
}
/**
* Utiliser pour r�soudre les entit�es (DTD & Sch�ma)
*
* @param publicId Id public <CODE>null</CODE> si non utilis�
* @param systemId Id service <CODE>null</CODE> si non utilis�
* @throws SAXException Exception en cas d'erreur, ce cache ne le
lance jamais
* @throws IOException En cas d'erreur non lanc�
* @return Le stream cach�
*/
public InputSource resolveEntity(java.lang.String publicId,
java.lang.String systemId) throws org.xml.sax.SAXException,
java.io.IOException {
if (
((this.systemId == null) || ( (this.systemId != null) &&
this.systemId.equals(systemId) )) &&
((this.publicId == null) || ( (this.publicId != null) &&
this.publicId.equals(publicId) ))
) {
if (in != null)
return new InputSource(in);
else
return null;
} else {
return null;
}
}
}
I don't know if it's the correct way to do so, but it worked with Xerces
1.4.2.
Hope this helps,
Eric
-----Original Message-----
From: Dmitri Toubelis [mailto:[EMAIL PROTECTED]]
Sent: jeudi 30 ao�t 2001 16:19
To: [EMAIL PROTECTED]
Subject: Including schema from jar file
Does anybody knows an easy way to include schema from jar file into xml
document. It seems like java URL doesn't work for that.
-Dmitri
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]