I'm not sure that my question is correct from EMF expert point of view. I investigate the problem
I have xml file that describe domain model(set of datatypes) and corresponded xsd file that can be used for validation given domain model description
This xml file can be changed by third party software. This updated is provided very seldom (one/two times in 3-4 months). In this case saving domain model as set of java class and rebuild it more suitable from other parts of application point of view
My goal is convert xml domain model to EMF domain model description, then generate genmodel file and then generate domain model as set of Java classes. how to convert xml domain model to EMF domain model description automatically? I found easy way to create ecore file from xsd. Are the any way to load my xml file using ecore description and save it as EMF like model for genearting Java class as next step
Thank you in advance
Alexander
As you yourself found out, you need to crate emf model out of schema.
Steps which I could immediately think of
Create ecore out of schema.
Generate genmodel.
Generate model, edit and editor.
Open manifest editor of generated editor plugin and check what is the file extension of your model instance file. This is the file extension which your xml file will stand with
Right click on generated project and launch as eclipse application.
Create a project and place your xml file with same extension as in step 4.
Double click on the file.
Now your xml file is loaded into emf model and displayed in editor. Now its your task to build your own UI based on your customer needs using the emf model.
Please note that you can always update the schema file, generate ecore file, update the existing model. Let me know if you need some more information.
Related
I am developing some tool using eclipse emf modeling and I would like to know how to get the xml line number of an parsed object. I need this in order to create file problem markers during data validation. I read some topics about this but I couldn't find the information I was looking for. I was thinking that maybe somebody can help me with some hints regarding how to do that.
Thanks.
I don't know if EMF provides this feature.
I haven't tried it but would start looking into how you can customize the XML deserialization process. It's possible to store the line number of each XML DOM node during de-serialization process. With XMLResource.getDOMHelper() you should be able to build a mapping between XML nodes and EMF objects. Using this mapping it should be possible to associate each EMF object with a line in XML file.
I have multiple data files (own XML formats, XSD Schema available for each format) which I want to load into my Eclipse RCP. I thought about of using EMF for that task and find several information about it. Is it possible to have exactly one EMF model (which is - as far as I know - saved as XMI file) which uses the model instance which is build of all XML files?
I know that I can generate the EMF model from the XSD-Schema. But I did not read that I am able to store the model instance in XML files corresponding to that Schemas. Is there any way to do that?
Surely I can use JAXB for that because in particular the task descriped above can be done with any XML binding tool. But rather than only binding XML I thought of EMF Forms or EMF Validation to work with that data.
Best regards
Yes, you can actually load EMF instances from XML documents that conform to your XSD.
Make sure that PDE, EMF and XSD SDK are installed. Then either create a new EMF project or create a new EMF Generator model in an existing project using the "File -> New" wizard. In the process, you can select "XML Schema" in the "Model Importers" step.
When you do this, you will see in the genmodel that the GenPackage's "Resource Type" (in the "Model" category) is set to "XML".
PS: You may also want to use the org.eclipse.wst.xml.core.catalogContributions extension point in plugin.xml to register your XSD in Eclipse's XML catalog.
I have a Java file that has XML annotations and I have an XSD file related to it. I want to generate a form at web page using that XSD file (dynamically). If a field is required I will put a mark at form field that shows it is a required field. User will fill fields. I will save it as an XML file and I will validate it against my XSD file. If a non valid situation occurs I will show it to user.
What can I use to achieve my purpose. What do you suggest for my architecture?
My requirement is to read an XSD file and to get all its elements with corresponding attributes in java. I've been trying to convert my XSD file to a sample XML file as parsing an XML file to get all it's elements and attributes is easy. But so far I've been unable to find a good enough tool in java to programmatically convert my XSD to sample XML.
Is there any free and good java code available to convert an XSD to its sample XML?
Or else what is the way I can read all the elements and attributes that a sample XML would contain directly from the XSD file?
Thanks in advance!
Processing a raw XSD document as XML is quite tricky except in very simple cases.
Alternatives are:
(a) use an API for accessing a compiled schema (for example, there is such an API in Xerces)
(b) Saxon's schema processor can output an XML representation of the compiled schema, which is much easier to process than the raw XSD documents (for example, it combines everything into one document, and presents the relationship of elements to types in a uniform way).
The xsd format is perfectly valid XML, so you can parse an XML schema file with any xml parser.
Check this related post to get some code samples and ideas:
Java API to parse XSD schema file
Not sure if this solves the problem. I have similar requirement of accessing elements and attributes of xsd. Using Eclipse, the solution to create XML out of xsd is quite easy. I have a dynamic web project created and put my xsd in webcontent. Right click on XSD and there is option called 'Generate'. It shows 2 options to generate XML or JAXB classes. On clicking Generate XML, XML file is created from XSD. I hope you were looking for this solution.
There is a tool in java to convert my XSD to sample XML. You need to add jaxb-xjc (executable jar file) in the build path of your project.Once you are done with it just put the .xsd file in src, right click on it and find 'Generate' option, you can now find XML and Jaxb classes against 'Generate' option, Select Xml and get your XML file generated from .xsd.
Is there a open source or commercial component for a visual xml tree editor? It should parse an xml file and allow the user to easily edit nodes, attributes etc.
Basically, user also needs to be able to add nodes in real time.
The Eclipse editor have a pretty good xml editor. It can show xml in source and in tree-like view.
http://www.eclipse.org/
Well, you can write one by your self. Just parse the file and you can use a JTreeTable (swingx) to render it and manipulate it dynamically.
You can see this post:
java-lib for xml tree visualization
The answer by Kumar has an example on how to proceed
Here is the excellent article for generating a tree view structure based on the given xml file on the fly.
http://www.developer.com/xml/article.php/3731356/Displaying-XML-in-a-Swing-JTree.htm
once the tree structure is generated you have to write your own logic to edit , add nodes.