Referencing xsds inside jars?

This should cover W3C XML Schema, Relax NG and DTD related problems.
jruud
Posts: 4
Joined: Tue Mar 21, 2006 9:58 pm

Referencing xsds inside jars?

Post by jruud »

We would prefer to store many of our xsds inside jars, but must be able to reference them in xs:import statements from other xsds. Is there some way to make this work for example by using XML catalogs (i.e. is it possible to set up a mapping so that 'schemaLocation='http://myurl/myxsd.xsd'/>' will resolve to for example myjar.jar!myxsd.xsd)? If not, would it be possible to replace/extend the XML editor's 'entity resolver' in order to look inside jar, or provide some other way of accessing xsds inside jars?

Thanks, John
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Post by Radu »

Hi John,

Maybe this sample would help:

1) I created a jar file called "jsp.jar" in the file system path:

Code: Select all

file:/C:/workspace/eXml/frameworks/jsp/xsd/
. The jar contains a directory called "jsp" and inside it a schema called "jspxsd.xsd".

2)The catalog file looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://java.sun.com/dtd/jspxml.xsd"
uri="jar:file:/C:/workspace/eXml/frameworks/jsp/xsd/jsp.jar!/jsp/jspxsd.xsd"/>
</catalog>
I went to Options->Preferences->XML Catalog and added my catalog to the list.

3)The schema file looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="http://java.sun.com/dtd/jspxml.xsd" namespace="http://www.w3.org/2001/XMLSchema"/>
</xs:schema>
When validated, the schema will resolve the "schemaLocation" reference through the custom catalog above (I checked both in Eclipse and the standalone version).

Here are some samples of using the "jar" protocol:


Local access:

Code: Select all

jar:file:/E:/local/folder/thepackage/thepackage.jar!/thepackage/images/blueball.gif
Remote access:

Code: Select all

jar:http://www.oxygenxml.com/thepackage.jar!/thepackage/blueball.gif
As you can see you prepend the "jar:" protocol to the URL, then at the end of the URL you append "!/" and the append the path through the jar archive to the resource.

You can also check that you created the right URL by trying to open it in Firefox (IE does not seem to handle the "jar" protocol) . Setting the XML Catalog in Oxygen to verbose would also help.

Regards, Radu
jruud
Posts: 4
Joined: Tue Mar 21, 2006 9:58 pm

Post by jruud »

Thanks Radu, I tried doing something similar earlier but couldn't get it to work. Your example made all the difference (it now works)

Thanks, John
Post Reply