Guest User

Untitled

a guest
Jul 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <empleado>
  2. <nombre>juan</nombre>
  3. <segundo_nombre>pablo</segundo_nombre>
  4. <apellido>perez</apellido>
  5. <dni>9999</dni>
  6. <calle>San martin</calle>
  7. <numero_calle>123</numero_calle>
  8. <piso>4r</piso>
  9. </empleado>
  10.  
  11. @XmlAccessorType(XmlAccessType.NONE)
  12. @XmlRootElement(name = "empleado")
  13. public class Empleado implements Serializable {
  14. @XmlElement(name = "nombre", required = true)
  15. private String nombre;
  16. @XmlElement(name = "segundo_nombre", required = true)
  17. private String segundo_nombre;
  18. @XmlElement(name = "dni", required = true)
  19. private String dni;
  20. private Direccion direccion = new Direccion();
  21.  
  22. @XmlRootElement(name = "empleado")
  23. @XmlAccessorType(XmlAccessType.NONE)
  24. public class Direccion implements Serializable {
  25. private String calle;
  26. private String numero_calle;
  27. private String piso;
  28.  
  29. public static void main(String[] args) throws Exception {
  30. try {
  31. //getting the xml file to read
  32. File file = new File("Empleado.xml");
  33. System.out.println("{} processing fileName='{}'" + file);
  34.  
  35. //creating the JAXB context
  36. JAXBContext jContext = JAXBContext.newInstance(Direccion.class, Empleado.class);
  37. //creating the unmarshall object
  38. unmarshaller = jContext.createUnmarshaller();
  39. //calling the unmarshall method
  40. Empleado emp = (Empleado) unmarshaller.unmarshal(file);
  41. System.out.println(emp.toString());
  42. } catch (Exception e) {
  43. e.printStackTrace();
  44. }
  45. }
  46.  
  47. > Empleado{nombre=juan, segundo_nombre=pablo, dni=9999,
  48. > direccion=Direccion{calle=null, numero_calle=null, piso=null}}
Add Comment
Please, Sign In to add comment