(Java, EMF) Create valid XML file from XSD
开发者_运维百科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
I think you are searching JAXB binding. You can parse .xsd file and generate (create) new .xml file with it
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!!
Try XMLBeans .
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
with XMLResourceFactoryImpl
... or something like that.
精彩评论