简体   繁体   中英

(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!!

试试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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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