Wed Jul 08, 2009 12:23 am
import jaxbclasses.studentType;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class UnmarshallingTest {
public static void main (String [] args) {
try {
JAXBContext jc = JAXBContext.newInstance ("jaxbclasses");
Unmarshaller u = jc.createUnmarshaller ();
File f = new File ("student.xml");
JAXBElement element = (JAXBElement) u.unmarshal (f);
studentType student= (studentType) element.getValue ();
System.out.println ("Student Gender is : " + student.getGender ());
System.out.println ("Student Name is : " + item.getName ());
System.out.println ("Student Age is : " + item.getAge ());
} catch (JAXBException e) {
e.printStackTrace ();
}
}
}
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="student" type="studentType"/>
<xsd:complexType name="studentType">
<xsd:sequence>
<xsd:element name="gender" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="age" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Wed Jan 26, 2011 12:43 pm
System.out.println ("Student Name is : " + student.getName ());
System.out.println ("Student Age is : " + student.getAge ());
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.