When I have a java object say Person and I have an XSD can I generate an output XML file. I heard a collega saying something about SAX and DOM parsers.
But reading through the API I only see the other way around. Going from XML to a Java object.
Since XML is just text, you could create output with println type character output statements. It would be up to you to write text compatible with the XSD.
For objects compatible with the JavaBean standard there is the java.beans.XMLEncoder class
Don't expect some magic tool that can look at the XSD and create complete code.
Creating unmarshalling code via an XSD is a largely automatic process via most any JAXB implementation.
pranay hira
Greenhorn
Joined: Jun 26, 2006
Posts: 15
posted
0
okay guess my collegue misunderstood. I did found this:
JAXBContext contextObj = JAXBContext.newInstance(Student.class);
Student myStudent = new Student();
Marshaller marshallerObj = contextObj.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
myStudent.setGender("M");
myStudent.setName("Amar");
myStudent.setAge(20);
marshallerObj .marshal(myStudent, new FileOutputStream("Student.xml"));