Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <empleado>
- <nombre>juan</nombre>
- <segundo_nombre>pablo</segundo_nombre>
- <apellido>perez</apellido>
- <dni>9999</dni>
- <calle>San martin</calle>
- <numero_calle>123</numero_calle>
- <piso>4r</piso>
- </empleado>
- @XmlAccessorType(XmlAccessType.NONE)
- @XmlRootElement(name = "empleado")
- public class Empleado implements Serializable {
- @XmlElement(name = "nombre", required = true)
- private String nombre;
- @XmlElement(name = "segundo_nombre", required = true)
- private String segundo_nombre;
- @XmlElement(name = "dni", required = true)
- private String dni;
- private Direccion direccion = new Direccion();
- @XmlRootElement(name = "empleado")
- @XmlAccessorType(XmlAccessType.NONE)
- public class Direccion implements Serializable {
- private String calle;
- private String numero_calle;
- private String piso;
- public static void main(String[] args) throws Exception {
- try {
- //getting the xml file to read
- File file = new File("Empleado.xml");
- System.out.println("{} processing fileName='{}'" + file);
- //creating the JAXB context
- JAXBContext jContext = JAXBContext.newInstance(Direccion.class, Empleado.class);
- //creating the unmarshall object
- unmarshaller = jContext.createUnmarshaller();
- //calling the unmarshall method
- Empleado emp = (Empleado) unmarshaller.unmarshal(file);
- System.out.println(emp.toString());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- > Empleado{nombre=juan, segundo_nombre=pablo, dni=9999,
- > direccion=Direccion{calle=null, numero_calle=null, piso=null}}
Add Comment
Please, Sign In to add comment