using xsd in jar to validate

B

Bounz

Hello,

I have a set of XML Schemas and a Xerces DOM parser that is supposed to
use those xsd to validate an XML.

My problem is that I want to put the xsd and the parser in the same jar
and enable the parsing of xml without having to specify the xsd location
in the xml. Since the xsd are in the jar, I cannot use the
DOMParser.setProperty() to specify the xsd location (or can I, but how?)

Do you know a way to do such a thing? Is it even possible?

Thanks

Antoine Brun
 
H

Henry S. Thompson

In principle you should be able to use a jar: URL to identify your
schema document -- I don't know whether Xerces will do the right thing
or not.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
C

Charles Fineman

Dunno if the parser can get resources from the jar but you could
probably do it by hand. Xerces allows you to cache "grammars" so you
could prepopulate the cache by doing "getResourceAsStream" to get the
xsd out of the jar and load it.
 
L

Laurens

Catalogs are your friends: http://www.xml.com/pub/a/2004/03/03/catalogs.html

You can also pass the URL of the XSD to the DocumentBuilderFactory.

DocumentBuilderFactory dbf;
dbf.setValidating(validate);
dbf.setNamespaceAware(true);
dbf.setAttribute(http://java.sun.com/xml/jaxp/properties/schemaLanguage,
"http://www.w3.org/2001/XMLSchema");
URL xsdURL = cl.getResource("my/package/my.xsd");
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
jxlURL.toString());

I bet that for SAX there's a similar mechanism to configure the Schema.
Anyway, catalogs offer the most comprehensive solution.


Regards
-Laurens
 
B

Bounz

Charles said:
Dunno if the parser can get resources from the jar but you could
probably do it by hand. Xerces allows you to cache "grammars" so you
could prepopulate the cache by doing "getResourceAsStream" to get the
xsd out of the jar and load it.

Hello, thanks for the answer, I found a way to get resource from a jar
and it works fine, but you talk about caching grammars. How do you do
such a thing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top