Schema locations [message #586275] |
Thu, 29 April 2004 11:03 |
Mike Lischke Messages: 78 Registered: July 2009 |
Member |
|
|
Hi group,
Currently I'm trying to find a consistent solution to load an XML schema
together will all its imported, included and redefined schemas. Until now
I have two versions to load schemas. One loads a schema fine when it is
located in an Eclipse project (with relative path name). It can also load
the schema from the file system when given with absolute path.
XSDResourceImpl xsdSchemaResource = new XSDResourceImpl();
xsdSchemaResource.setURI(URI.createURI(schemaName));
InputStream stream =
getClass().getClassLoader().getResourceAsStream(schemaName);
if (stream == null)
stream = new FileInputStream(schemaName);
if (stream != null)
{
try
{
xsdSchemaResource.load(stream, null);
schemas.add(xsdSchemaResource.getSchema());
}
catch(Exception e)
{
...
}
}
The second one can load schemas from the file system when I specify the
file:// protocol.
URI uri = URI.createURI(schemaLocation);
ResourceSet resourceSet = new ResourceSetImpl();
XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.getResource(uri, true);
schemas.add(xsdResource.getSchema());
My problem is now: the second version also loads all included etc. schemas
so I have the full hierarchy (which is the final goal for me). But it does
only so when given an absolute file (or another valid URI I suppose,
haven't tried). It cannot load schemas from the resource of an Eclipse
project. The first version in contrast does not load included schemas, but
only loads the main file.
So my question is: How can I make a combined version so that regardless of
the actual location of the schema (URL, local file, resouce file -> maybe
in jar) the main schema file and all those, which are referenced by it (or
recursively by the others) are loaded successfully?
I already looked at the traceLoading sample code, which uses an URI map,
however this does not help for resource files. I would need stream support
for a generic solution, but I have not found any stream reference in the
documentation.
Mike
--
www.soft-gems.net
|
|
|
Powered by
FUDForum. Page generated in 0.02528 seconds