There is one important trick for handling imports and includes automatically. You must use a ResourceSet to read the main XSD file.
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.xsd.util.XSDResourceFactoryImpl; import org.eclipse.xsd.util.XSDResourceImpl; import org.eclipse.xsd.XSDSchema; static ResourceSet resourceSet; XSDResourceFactoryImpl rf = new XSDResourceFactoryImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", rf); resourceSet = new ResourceSetImpl(); resourceSet.getLoadOptions().put(XSDResourceImpl.XSD_TRACK_LOCATION, Boolean.TRUE); XSDResourceImpl rsrc = (XSDResourceImpl)(resourceSet.getResource(uri, true)); XSDSchema sch = rsrc.getSchema();
Then, before processing an element, attribute, or model group, you should use this:
elem = elem.getResolvedElementDeclaration(); attr = attr.getResolvedAttributeDeclaration(); grpdef = grpdef.getResolvedModelGroupDefinition();
source share