Create XML from Input Data file and XSD file

OmarJareno

New Member
I have referred to How to generate sample XML documents from their DTD or XSD? on this topic, But i didn't get exactly what i was looking for.I have an XSD and my Data file as an input. I wish to generate .XML file out of that. I would like to write a Java Code which should be generic one, i.e. it should except any .xsd and its data file to create .xml file and I don't want to change the calling setters names and calling class name when xsd changes.In other words, i need to generate calling class as per the xsd to generate xml. I tried JAXB to create .xml from .xsd. For Examle:Hello.java\[code\]import java.io.*;import java.util.*;import javax.xml.bind.*;import hello.*;public class Hello { private ObjectFactory of; private GreetingListType grList; public Hello(){ of = new ObjectFactory(); grList = of.createGreetingListType(); } public void make( String t, String l ){ GreetingType g = of.createGreetingType(); g.setText( t ); g.setLanguage( l ); grList.getGreeting().add( g ); } public void marshal() { try { JAXBElement<GreetingListType> gl = of.createGreetings( grList ); File file = new File("jaxb_hello.xml"); JAXBContext jc = JAXBContext.newInstance( "hello" ); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal( gl, System.out ); m.marshal( gl, file); } catch( JAXBException jbe ){ // ... } } public static void main(String args[]) { Hello h = new Hello(); h.make( "Bonjour, madame", "fr" ); h.make( "Hey, you", "en" ); h.marshal(); }}\[/code\]I am not sure if there exist any free library or tool on unix environment to achive this.If there isn't any, i will try to code it down. Some references would be of great help.
 
Back
Top