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?
Related
I'm trying to create a PDF from a template in my backend and then serve it to the user when it needs to download it. The only problem that I have is that one of the fields in that template must have HTML source in it and must be rendered. Is there any way to add HTML source in that field and render it ? I am currently using PDFBox.
So I have about 950 XML files that I need to read, I have the Java classes for those XML files generated using an .xsd and a binding .xjb file.
My problem is that I need this code to be interchangeable, meaning it must be able to read different XML files with different tags, and still be able to return these values. I've tried using method.invoke to invoke all the get methods, but they aren't returned in a specific order, which doesn't help since I will need these values in an order to place it in a .csv file.
So if anyone can help me achieve this, it would be greatly appreciated.
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.