Loading an existing XML Schema model is relatively
simple if you use the default platform protocol resolver
"platform:/resource". You may want to implement an
org.eclipse.emf.ecore.resource.URIConverter to resolve
resources that might not be found using the default
platform protocol resolver. Some of these could include
XML Schema files located in a plug-in directory or
somewhere on the World Wide Web.
The following listing shows how to load
any XML Schema file within the Eclipse workspace using
the default platform protocol resolver.
public XSDSchema loadXSDSchema(IFile xsdFile)
{
try
{
//Create a resource set to manage the resources
ResourceSet resourceSet = new ResourceSetImpl();
//Let the resource set load the resource from the given uri
XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.
createURI("platform:/resource" + xsdFile.getFullPath()), true);
//The contents of the resource is the root XSDSchema object
XSDSchema xsdSchema = xsdResource.getSchema();
return xsdSchema;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}