(Java、EMF)从 XSD 创建有效的 XML 文件
我想根据给定的 XSD 架构文件创建一个 XML 文件。是否有任何开源框架可用于该任务?
目前,我正在使用 EMF 并加载 XSD 文件(实际上,主文件中有多个链接)并创建了相应的模型和 Java 代码。目前,我无法弄清楚如何从此 EMF 模型创建有效的 XML 实例文件。此外,我不知道 EMF 是否是正确的框架。
感谢您的帮助和来自德国
Marco 的问候
I want to create a XML file according to a given XSD schema file. 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. Currently, I cannot figure out how to create the valid XML instance file from this EMF model. Besides, I don't know if EMF is the right framework for that.
Thanks for your help and greets from Germany
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您正在搜索 JAXB 绑定。您可以解析 .xsd 文件并用它生成(创建)新的 .xml 文件
I think you are searching JAXB binding. You can parse .xsd file and generate (create) new .xml file with it
看看这个:
http:// help.eclipse.org/help33/index.jsp?topic=/org.eclipse.emf.doc/tutorials/xlibmod/xlibmod.html
然后,自动为您的ecore模型生成测试(右键单击根目录) ecore 模型的元素并选择诸如“生成测试代码”或“生成模型测试”之类的内容)。
在这些测试中,您将找到用于生成模型实例的有效 XML 文件的代码。
干杯!!
just take a look on this:
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").
In those test you will find code to generate valid XML files of your model instances.
cheers!!
尝试 XMLBeans 。
Try XMLBeans .
EMF 教程。搜索标题为“保存和加载资源”的部分。该示例显示使用 XMI 进行加载和保存。 IIRC,您可以使用纯 XML 而不是 XMI,只需将
XMIResourceFactoryImpl
替换为XMLResourceFactoryImpl
...或类似的东西。There's some material on doing this in the EMF Tutorial. Search for the section entitled "Saving and loading resources". The example shows loading and saving using XMI. IIRC, you can use plain XML rather than XMI by simply replacing
XMIResourceFactoryImpl
withXMLResourceFactoryImpl
... or something like that.