Referencing xsds inside jars?

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 4

Referencing xsds inside jars?

Tue Mar 21, 2006 10:00 pm

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
Posts: 5378

Wed Mar 22, 2006 10:02 am

Hi John,

Maybe this sample would help:

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

Code: Select all

. 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"
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> 
  <system systemId=""

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="">
    <xs:import schemaLocation="" namespace=""/>

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


Remote access:

Code: Select all


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
Posts: 4

Thu Mar 23, 2006 5:56 am

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

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest