This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Using schema files in a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Using schema files in a jar" Watch "Using schema files in a jar" New topic
Author

Using schema files in a jar

Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
I want to be able to package my app in a jar file including all schema (xsd) files.

I am using JDOM w/xerces as its parser. I know how to configure the parser through JDOM to use schema validation and to specify an external schema file residing on the file system.

But, I am unsure of how to instruct the parser to validate using the jarred schema files? i.e. How can the parser read from the jar?

I read on some post about creating a custom EntityResolver that uses the classpath to locate the schema file but I'm just wondering if there is a better solution?


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

YourClass.getClass().getResourceAsStream( .. ) will load it from the classpath


Regards,

Pho
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Originally posted by Pho Tek:
YourClass.getClass().getResourceAsStream( .. ) will load it from the classpath
That would work if I could simply pass the InputStream to the parser, but I'm not aware of any way to do that.

For example, according to the JDOM docs, to tell the parser where the schema file is:Where weblog.xsd is the file spec.

So, unless I'm missing something, it looks as though you have to specify the location as a file spec. But it seems like there should be a mechanism built into the parser to load it from the classpath instead.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
ok, I believe I found the solution to my problem.
The schema location can also be a URL string so I can use ClassLoader.getResource() which returns the URL (jar:...) of the schema file. Then I can simply do this:Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using schema files in a jar
 
Similar Threads
UPS Online Tools
How can I validate the XML schema with XML files using localpath?
JDOM alternative JAR file required
CDATA and jdom
Help !! Parsing Schema