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.
Related
I have to generate word documents from my application against a entity which will contain some information about that entity, for this i am using POI. But while using POI i have to decide like where i have to create a paragraph, where i have make text bold\italic etc based on a configuration in entity object which i could easily handle in the code.
But is there any way so that i can just define all these style/alignments etc information in any XML/XSL or in any other type of config so i can get rid of styling in my java code ?
Regarding your title question, see Where can I find the XSDs of DOCX XML files?
Regarding your body question,
But is there any way so that i can just define all these
style/alignments etc information in any XML/XSL or in any other type
of config so i can get rid of styling in my java code ?
Yes, of course, and it would be a wise design decision to do so. Since DOCX is OOXML (within OPC) your XSLT will be able to generate OOXML character level formatting via w:rPr settings such as w:b, w:i, etc.
The challenge you'll be facing, however, is that you'll be forgoing the convenience provided by the POI API. You'll also have to reconstruct the OPC if you want to produce a proper DOCX file rather than just an importable OOXML file. For small projects, the learning curve required to wield OOXML directly is likely to be too steep to merit a direct-to-OOXML approach.
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'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.
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.
I have an XML schema file. I want to use Java to open this file, find all elements, extract their names, and write them to a text file. I have tried various libraries, but I could not get this to work. Please suggest any libraries or other methods that will work.
XSD files are XML files so you can use any suitable XML processing library to parse it.
I don't think you'll find a library that exists for your purpose, you'll have to write one yourself. The XSD is simply an XML file that conform to the schema:
Traverse the file as normal using DOM or SAX or whatever your preference is.
I assume you are looking for the information conveyed by the XML Schema. I would recommend you the XSOM library, it takes away dealing with the XML itself; nonetheless, a basic understanding of what can be described by an XSD is most likely required.
Follow the user guide, there are some examples showing how to move towards what you need.