简体   繁体   English

(Java,EMF)从XSD创建有效的XML文件

[英](Java, EMF) Create valid XML file from XSD

I want to create a XML file according to a given XSD schema file. 我想根据给定的XSD模式文件创建XML文件。 Are there any open source frameworks to use for that taks? 是否有任何开源框架可用于这些任务?

Currently, I am playing with EMF and loaded the XSD files (actually, there are several linked in a main file) and created the corresponding model and Java code. 当前,我正在使用EMF并加载XSD文件(实际上,在主文件中有多个链接),并创建了相应的模型和Java代码。 Currently, I cannot figure out how to create the valid XML instance file from this EMF model. 目前,我无法弄清楚如何从该EMF模型创建有效的XML实例文件。 Besides, I don't know if EMF is the right framework for that. 此外,我不知道EMF是否是正确的框架。

Thanks for your help and greets from Germany 感谢您的帮助和来自德国的问候

Marco 马尔科

I think you are searching JAXB binding. 我认为您正在搜索JAXB绑定。 You can parse .xsd file and generate (create) new .xml file with it 您可以解析.xsd文件并使用它生成(创建)新的.xml文件

just take a look on this: http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.emf.doc/tutorials/xlibmod/xlibmod.html 请看一下: http : //help.eclipse.org/help33/index.jsp?topic=/org.eclipse.emf.doc/tutorials/xlibmod/xlibmod.html

Then, generate the tests automatically for your ecore model (right click on the root element of the ecore model and select something like "generate test code" or "generate model tests"). 然后,自动为您的ecore模型生成测试(右键单击ecore模型的根元素,然后选择“生成测试代码”或“生成模型测试”之类的内容)。 In those test you will find code to generate valid XML files of your model instances. 在那些测试中,您将找到用于生成模型实例的有效XML文件的代码。

cheers!! 干杯!!

试试XMLBeans

There's some material on doing this in the EMF Tutorial . EMF教程》中提供了一些有关执行此操作的材料。 Search for the section entitled "Saving and loading resources". 搜索标题为“保存和加载资源”的部分。 The example shows loading and saving using XMI. 该示例显示了使用XMI进行加载和保存。 IIRC, you can use plain XML rather than XMI by simply replacing XMIResourceFactoryImpl with XMLResourceFactoryImpl ... or something like that. IIRC,您可以简单地用XMLResourceFactoryImpl替换XMIResourceFactoryImpl ...或类似的东西,而不是XMI来使用纯XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM