公告
财富商城
积分规则
提问
发文
2019-02-13 10:42发布
▲ chillily
What is the best way to convert .xsd-files into .ecore-files?
.xsd
.ecore
Is there an Eclipse plugin for that?
An example class. I did not clean up the imports.
import org.eclipse.emf.common.util.URI; import java.io.IOException; import java.util.Collection; import java.util.Iterator; import org.eclipse.emf.ecore.*; import org.eclipse.xsd.*; import org.eclipse.xsd.ecore.XSDEcoreBuilder; 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.emf.ecore.xmi.*; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.eclipse.emf.edit.ui.*; public class Xsd2Ecore { public static void main(String[] args) { Xsd2Ecore x2e = new Xsd2Ecore(); x2e.go("UMLVersions/V1.0.0/UML2XMI.xsd", "UMLVersions/V1.0.0/UML2100.xmi"); } public void go(String sourcename, String targetname) { System.out.println("Starting"); XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder(); ResourceSet resourceSet = new ResourceSetImpl(); Collection eCorePackages = xsdEcoreBuilder.generate(URI.createFileURI(sourcename)); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createFileURI(targetname)); for (Iterator iter = eCorePackages.iterator(); iter.hasNext();) { EPackage element = (EPackage) iter.next(); resource.getContents().add(element); } try { resource.save(null); } catch (IOException e) { e.printStackTrace(); } System.out.println("Finished"); } }
That's what worked for me:
To revalidate the .ecore-File when xsd has changed:
Have you tried
eclipse –console –noExit –noSplash -data C:\temp\emf-ws -application org.eclipse.xsd.ecore.importer.XSD2GenModel
It generates .ecore and .genmodel for your set of XSDs.
If you do not want to create a new MDT project every time you want to import a schema as ECore model then there is also another way to do this:
最多设置5个标签!
An example class. I did not clean up the imports.
That's what worked for me:
To revalidate the .ecore-File when xsd has changed:
Have you tried
It generates .ecore and .genmodel for your set of XSDs.
If you do not want to create a new MDT project every time you want to import a schema as ECore model then there is also another way to do this: