Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XSDSchema Loading
XSDSchema Loading [message #602378] Mon, 18 June 2007 21:44
Eclipse User
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);

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;
}
Previous Topic:complexType mapped to EDataType
Next Topic:XSDSchema Loading
Goto Forum:
  


Current Time: Wed Sep 24 00:32:09 GMT 2014

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

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