将.xsd
- 文件转换为.ecore
- 文件的最佳方式是什么?
是否有Eclipse插件?
答案 0 :(得分:8)
这对我有用:
在xsd更改时重新验证.ecore文件:
答案 1 :(得分:6)
如果您不希望每次要将架构导入为ECore模型时都创建新的MDT项目,那么还有另一种方法可以执行此操作:
答案 2 :(得分:3)
示例类。我没有清理进口货物。
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");
}
}
答案 3 :(得分:0)
你试过吗
eclipse –console –noExit –noSplash -data C:\temp\emf-ws
-application org.eclipse.xsd.ecore.importer.XSD2GenModel
它为您的XSD集生成.ecore和.genmodel。