Hi Kevin,

One solution to your problem is to register your own entity resolver [1]
on the parser. Given the URI of the schema passed to the entity
resolver, you can retrieve it from another source, such as from within a
jar. You can then return an InputSource containing the InputStream or
Reader you've opened (or another URI for the parser to read from).

If your document references are relative URIs you need to set the system
ID on the InputSource otherwise Xerces will resolve them relative to the
directory where Java was launched. Certainly not the behaviour most users
expect but with an InputStream alone there is no context for resolving
relative URI references. You must provide this base URI if parsing your
document requires resolving external entities.

Hope that helps.

[1]
http://xml.apache.org/xerces2-j/javadocs/api/org/xml/sax/EntityResolver.html

On Wed, 8 Oct 2003, Kevin Klinemeier wrote:

> I'm having a problem using the Xerces-J to validate my XML file against
> a schema.
>
> If I load the file by uri, then everything works fine (it references
> its own schema).
>
> However, this XML file may be included in a jarfile, and so I really
> want to load it via this.getClass().getResourceAsStream(...).  That
> works fine like this:
>
> parser.parse(new
> InputSource(this.getClass().getResourceAsStream(REPOSITORY_FILENAME)));
>
> That works, except it no longer knows where to look for the schema
> file.
>
> I looked at using the properties:
>
> http://apache.org/xml/properties/schema/external-schemaLocation
> or
> http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
>
> These both take a filename, which I don't have access to in the jar
> context.  And, even if I'm able to avoid the jar context, I really want
> to avoid having a .properties file with "xmlLocation=blahblah" that has
> to be maintained by each developer.
>
> Is there another solution I'm missing?  Perhaps one that allows me to
> specify a schema by an input stream?
>
> -Kevin Klinemeier
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to