Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Problem reading imported schemas with absolute path
Problem reading imported schemas with absolute path [message #73473] Wed, 12 December 2007 22:48 Go to next message
Eclipse UserFriend
Originally posted by: sdjuricic.galdosinc.com

Hello,

I have a problem when loading imported schemas that have schemaLocation
set with an absolute path without the file protocol prefix. The main
schema will be loaded but the imported schemas will not be loaded. All
the xsd files are located on my file system. If I change the
schemaLocation to be a relative path to the main schema then I do not have
an issue. The only way how all schemas will be loaded with absolute path
is if schemaLocation contains the file protocol prefix
example. file://C:/folderA/A.xsd

Is there a way to load all resources when the schemaLocation contains only
the absolute path without the file:// prefix? When loading without the
file:// even though schemas do not get loaded I don't get any error
messages about not being able to load imported schemas. Is there a way to
specify an error listener or to check for error if a particular imported
resource was not loaded.

I am using the following method to load the schemas. This method was just
copied from the example given.

URI uri;
String filePath = "C:/projects/test.xsd"
File file = new File(filePath);
if (file.isFile()) {
uri = URI.createFileURI(file.getCanonicalFile().toString());
} else {
uri = URI.createURI(filePath);
}
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( )
.put("xsd", new XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
XSDResourceImpl xsdMainResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
xsdMainResource.setURI(uri);
xsdMainResource.load(resourceSet.getLoadOptions());

for (Iterator resources = resourceSet.getResources().iterator();
resources.hasNext(); ) {
Object resource = resources.next();
if (resource instanceof XSDResourceImpl) {
XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
XSDSchema xsdSchema = xsdResource.getSchema();
}
Re: Problem reading imported schemas with absolute path [message #73490 is a reply to message #73473] Wed, 12 December 2007 23:16 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Srdjan,

Comments below.

Srdjan wrote:
> Hello,
>
> I have a problem when loading imported schemas that have
> schemaLocation set with an absolute path without the file protocol
> prefix.
The schema location is supposed to be a URI so a cleaning drive letter
followed by a ":" will look like a bad URI scheme.
> The main schema will be loaded but the imported schemas will not be
> loaded. All the xsd files are located on my file system. If I change
> the schemaLocation to be a relative path to the main schema then I do
> not have an issue. The only way how all schemas will be loaded with
> absolute path is if schemaLocation contains the file protocol prefix
> example. file://C:/folderA/A.xsd
Yes, that's what I would expect. It's suppose to be a URI not an
OS-specific file path.
>
> Is there a way to load all resources when the schemaLocation contains
> only the absolute path without the file:// prefix? When loading
> without the file:// even though schemas do not get loaded I don't get
> any error messages about not being able to load imported schemas. Is
> there a way to specify an error listener or to check for error if a
> particular imported resource was not loaded.
It's not an error for a schema to fail to load. You will get a warning
diagnostic if an import is unresolved. You can add an
XSDSchemaLocationResolve if you want to do special processing on the
schemaLocation value (such as adding the required file:// prefix.
>
> I am using the following method to load the schemas. This method was
> just copied from the example given.
>
> URI uri;
> String filePath = "C:/projects/test.xsd"
> File file = new File(filePath);
> if (file.isFile()) {
> uri = URI.createFileURI(file.getCanonicalFile().toString());
> } else {
> uri = URI.createURI(filePath);
> }
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( )
> .put("xsd", new XSDResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
> XSDResourceImpl xsdMainResource =
> (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
> xsdMainResource.setURI(uri);
> xsdMainResource.load(resourceSet.getLoadOptions());
>
> for (Iterator resources = resourceSet.getResources().iterator();
> resources.hasNext(); ) {
> Object resource = resources.next();
> if (resource instanceof XSDResourceImpl) {
> XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
> XSDSchema xsdSchema = xsdResource.getSchema();
> }
>
>
>
>
Re: Problem reading imported schemas with absolute path [message #602766 is a reply to message #73473] Wed, 12 December 2007 23:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Srdjan,

Comments below.

Srdjan wrote:
> Hello,
>
> I have a problem when loading imported schemas that have
> schemaLocation set with an absolute path without the file protocol
> prefix.
The schema location is supposed to be a URI so a cleaning drive letter
followed by a ":" will look like a bad URI scheme.
> The main schema will be loaded but the imported schemas will not be
> loaded. All the xsd files are located on my file system. If I change
> the schemaLocation to be a relative path to the main schema then I do
> not have an issue. The only way how all schemas will be loaded with
> absolute path is if schemaLocation contains the file protocol prefix
> example. file://C:/folderA/A.xsd
Yes, that's what I would expect. It's suppose to be a URI not an
OS-specific file path.
>
> Is there a way to load all resources when the schemaLocation contains
> only the absolute path without the file:// prefix? When loading
> without the file:// even though schemas do not get loaded I don't get
> any error messages about not being able to load imported schemas. Is
> there a way to specify an error listener or to check for error if a
> particular imported resource was not loaded.
It's not an error for a schema to fail to load. You will get a warning
diagnostic if an import is unresolved. You can add an
XSDSchemaLocationResolve if you want to do special processing on the
schemaLocation value (such as adding the required file:// prefix.
>
> I am using the following method to load the schemas. This method was
> just copied from the example given.
>
> URI uri;
> String filePath = "C:/projects/test.xsd"
> File file = new File(filePath);
> if (file.isFile()) {
> uri = URI.createFileURI(file.getCanonicalFile().toString());
> } else {
> uri = URI.createURI(filePath);
> }
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( )
> .put("xsd", new XSDResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
> XSDResourceImpl xsdMainResource =
> (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
> xsdMainResource.setURI(uri);
> xsdMainResource.load(resourceSet.getLoadOptions());
>
> for (Iterator resources = resourceSet.getResources().iterator();
> resources.hasNext(); ) {
> Object resource = resources.next();
> if (resource instanceof XSDResourceImpl) {
> XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
> XSDSchema xsdSchema = xsdResource.getSchema();
> }
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Problem reading imported schemas with absolute path
Next Topic:[Announce] Joint Eclipse/OMG Symposia
Goto Forum:
  


Current Time: Thu Apr 25 15:44:03 GMT 2024

Powered by FUDForum. Page generated in 0.03369 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top