I'm really new to XSD and XML (I know the basic XML such as elements and tags). I have an XSD files and I need to set the data on some of its elements and (some have list type) then convert it to XML file.
Can someone please give me an idea or overview on how can I do it? and what tools do I have to use?
Just to make sure we are on the same page, a XSD is a schema file defining the attributes and elements of a XML entity within an XML file (usually a file, but could be a stream, etc...). So, you don't really set elements in the XSD.
If you want to create XML entities from the XSD using Java, Java offers two robust APIs for working with XSD/XML file formats. The older JAXP, and the newer (more efficient) JAXB - Java Architecture for XML Binding. Assuming you are running Java SE 6 or greater, JAXB should be included. If you are using a legacy system, check out the CodeRanch XML FAQ for more information on JAXP.
Included with JAXB is a command line utility called xjc. That's where you will want to begin. xjc will convert a XSD into corresponding JAXB annotated Java classes. For more information, please review: https://jaxb.java.net/2.2.4/docs/xjc.html
Once you have the JAXB annotated Java classes, you'll need to look at creating XML output through a process called marshalling. As XML is often used in Web Services, Oracle has included instructions on JAXB as part of their Java EE guides. You can learn more about implementing JAXB here: https://docs.oracle.com/javaee/7/tutorial/jaxrs-advanced007.htm#GKKNJ
I have given an XSD file by my boss and a table in the database (that is changing, thousands of rows). I was given a task to create a java method that will generate an xml file using the values on the database upon invoking the said method.
I'm really not sure what to do to the XSD file and how to generate the XML out of XSD (setting the values from the database to the XML elements).
Tim Moores wrote:More useful than the XSD file would be an example XML file - XSDs generally describe an unlimited number of different XML files, so from that alone it is not possible to create an XML file.
Depends how complex the XSD is.
Or, more like it, is how flexible it is.
Most of the ones I've dealt with have been fairly tightly written, so figuring out the format of a valid XML file for it wouldn't be too much of an issue.
Something like the more obscure parts of OTA (the travel standard)? Possibly not so easy.