Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsXSDSchema Loading
https://www.eclipse.org/forums/index.php/mv/msg/22521/72401/#msg_72401
Originally posted by: kemoon.tin.it
Does anybody know how to load an xml schema from a file with import and
include directives linking to other files?
I have tried this solutiom, but it still doesn't work.
String schemaURL =
"../xmLegesEditor/xsdData/NIR_XSD_completo/nirstrict.xsd";
public static XSDSchema loadSchemaUsingResourceSet(String schemaURL)
throws Exception{
XSDResourceFactoryImpl resourceFactory = new XSDResourceFactoryImpl();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",resourceFactory);
return xsdResource.getSchema();
}
}
System.err.println("loadSchemaUsingResourceSet(" + schemaURL + ") did
not contain any schemas!");
return null;
}]]>2007-06-18T21:44:19-00:00Re: XSDSchema Loading
https://www.eclipse.org/forums/index.php/mv/msg/22521/602386/#msg_602386
If you run this under debug control (or add a print statement), what's
the value of schemaURL at the point when you call getResource? (As long
as you load using an absolute URI, all relative URIs should resolve
correctly to the same absolute URI they'd resolve to if you were loading
..html file in a browser.)
Francesca wrote:
> Does anybody know how to load an xml schema from a file with import
> and include directives linking to other files?
> I have tried this solutiom, but it still doesn't work.
> String schemaURL =
> "../xmLegesEditor/xsdData/NIR_XSD_completo/nirstrict.xsd";
>
> public static XSDSchema loadSchemaUsingResourceSet(String schemaURL)
> throws Exception{
>
> XSDResourceFactoryImpl resourceFactory = new
> XSDResourceFactoryImpl();
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",resourceFactory);
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./xlink.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/xlink.xsd "));//,URI.createURI("./xlink.xsd"));
>
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./h.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/h.xsd "));//,URI.createURI("./h.xsd"));
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./dsp.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/dsp.xsd "));//,URI.createURI("./dsp.xsd"));
> File file = new File(schemaURL);
> if (file.isFile())
> schemaURL =
> URI.createFileURI(file.getCanonicalFile().toString()).toStri ng();
>
> resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
> Boolean.TRUE);
>
> XSDResourceImpl xsdSchemaResource = null;
> try
> {
> xsdSchemaResource =
> (XSDResourceImpl)resourceSet.getResource(URI.createURI(schem aURL),true);
> }
> catch(Exception e)
> {
> System.err.println("Exception caught in method 'load schema using
> ResourceSet' message = " + e.getMessage() + " xsdSchemaResource: " +
> xsdSchemaResource);
> }
>
> for (Iterator resources =
> resourceSet.getResources().iterator();resources.hasNext(); /* no-op */)
> {
> Resource resource = (Resource)resources.next();
> if (resource instanceof XSDResourceImpl)
> {
> XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
> XSDSchema xsdSchema = xsdResource.getSchema();
> for (Iterator contents = xsdSchema.getContents().iterator();
> contents.hasNext(); )
> {
> XSDSchemaContent xsdSchemaContent =
> (XSDSchemaContent)contents.next();
> if (xsdSchemaContent instanceof XSDSchemaDirective)
> { XSDSchemaDirective
> xsdSchemaDirective = (XSDSchemaDirective)xsdSchemaContent;
> if (xsdSchemaDirective.getResolvedSchema() == null)
> {
> System.err.println("Unresolved schema "+
> xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());
>
> if(xsdSchemaDirective instanceof XSDImport)
> {
> XSDImport xsdSchemaImport =
> (XSDImport)xsdSchemaDirective;
> XSDSchema resolvedSchema =
> ((XSDImportImpl)xsdSchemaImport).importSchema();
> if(resolvedSchema != null)
> {
> System.err.println("-------> now
> resolved");
> xsdSchemaDirective.setResolvedSchema(resolvedSchema);
> ((XSDSchemaImpl)resolvedSchema).imported((XSDImport)xsdSchem aDirective);
> }
> }
>
> } else {
> System.err.println("Resolved schema "+
> xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());
> if(xsdSchemaDirective instanceof XSDImport)
> {
> XSDImport xsdSchemaImport =
> (XSDImport)xsdSchemaDirective;
> }
> } }
> }
> return xsdResource.getSchema();
> }
> }
> System.err.println("loadSchemaUsingResourceSet(" + schemaURL + ")
> did not contain any schemas!");
> return null;
> }
>
>]]>Ed Merks2007-06-18T23:09:01-00:00Re: XSDSchema Loading
https://www.eclipse.org/forums/index.php/mv/msg/22521/72419/#msg_72419
Originally posted by: merks.ca.ibm.com
Francesca,
If you run this under debug control (or add a print statement), what's
the value of schemaURL at the point when you call getResource? (As long
as you load using an absolute URI, all relative URIs should resolve
correctly to the same absolute URI they'd resolve to if you were loading
..html file in a browser.)
Francesca wrote:
> Does anybody know how to load an xml schema from a file with import
> and include directives linking to other files?
> I have tried this solutiom, but it still doesn't work.
> String schemaURL =
> "../xmLegesEditor/xsdData/NIR_XSD_completo/nirstrict.xsd";
>
> public static XSDSchema loadSchemaUsingResourceSet(String schemaURL)
> throws Exception{
>
> XSDResourceFactoryImpl resourceFactory = new
> XSDResourceFactoryImpl();
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xsd",resourceFactory);
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./xlink.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/xlink.xsd "));//,URI.createURI("./xlink.xsd"));
>
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./h.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/h.xsd "));//,URI.createURI("./h.xsd"));
> resourceSet.getURIConverter().getURIMap().put(URI.createURI( "./dsp.xsd"),URI.createURI(" file:/home/tommaso/schemaWorkspace/xmLegesEditor/xsdData/NIR _XSD_completo/dsp.xsd "));//,URI.createURI("./dsp.xsd"));
> File file = new File(schemaURL);
> if (file.isFile())
> schemaURL =
> URI.createFileURI(file.getCanonicalFile().toString()).toStri ng();
>
> resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_L OCATION,
> Boolean.TRUE);
>
> XSDResourceImpl xsdSchemaResource = null;
> try
> {
> xsdSchemaResource =
> (XSDResourceImpl)resourceSet.getResource(URI.createURI(schem aURL),true);
> }
> catch(Exception e)
> {
> System.err.println("Exception caught in method 'load schema using
> ResourceSet' message = " + e.getMessage() + " xsdSchemaResource: " +
> xsdSchemaResource);
> }
>
> for (Iterator resources =
> resourceSet.getResources().iterator();resources.hasNext(); /* no-op */)
> {
> Resource resource = (Resource)resources.next();
> if (resource instanceof XSDResourceImpl)
> {
> XSDResourceImpl xsdResource = (XSDResourceImpl)resource;
> XSDSchema xsdSchema = xsdResource.getSchema();
> for (Iterator contents = xsdSchema.getContents().iterator();
> contents.hasNext(); )
> {
> XSDSchemaContent xsdSchemaContent =
> (XSDSchemaContent)contents.next();
> if (xsdSchemaContent instanceof XSDSchemaDirective)
> { XSDSchemaDirective
> xsdSchemaDirective = (XSDSchemaDirective)xsdSchemaContent;
> if (xsdSchemaDirective.getResolvedSchema() == null)
> {
> System.err.println("Unresolved schema "+
> xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());
>
> if(xsdSchemaDirective instanceof XSDImport)
> {
> XSDImport xsdSchemaImport =
> (XSDImport)xsdSchemaDirective;
> XSDSchema resolvedSchema =
> ((XSDImportImpl)xsdSchemaImport).importSchema();
> if(resolvedSchema != null)
> {
> System.err.println("-------> now
> resolved");
> xsdSchemaDirective.setResolvedSchema(resolvedSchema);
> ((XSDSchemaImpl)resolvedSchema).imported((XSDImport)xsdSchem aDirective);
> }
> }
>
> } else {
> System.err.println("Resolved schema "+
> xsdSchemaDirective.getSchemaLocation() +" in " + xsdResource.getURI());
> if(xsdSchemaDirective instanceof XSDImport)
> {
> XSDImport xsdSchemaImport =
> (XSDImport)xsdSchemaDirective;
> }
> } }
> }
> return xsdResource.getSchema();
> }
> }
> System.err.println("loadSchemaUsingResourceSet(" + schemaURL + ")
> did not contain any schemas!");
> return null;
> }
>
>]]>2007-06-18T23:09:01-00:00