Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
XML Schema Infoset Model, Part 1
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
5. Working with XML Schema resources in Eclipse
  


Loading an XML Schema file page 2 of 3


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;
}

Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact