コード例 #1
0
  private static void unMarshalingExample() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(EmployeeList.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    EmployeeList emps =
        (EmployeeList)
            jaxbUnmarshaller.unmarshal(
                new File("src/example/java/xml/parser/jaxb/xml/employees-list-unmarshaling.xml"));

    for (Employee emp : emps.getEmployees()) {
      System.out.println(emp.getId());
      System.out.println(emp.getFirstName());
      System.out.println(emp.getLastName());
      System.out.println(emp.getIncome());
    }
  }
コード例 #2
0
  static {
    employees.setEmployees(new ArrayList<Employee>());

    Employee emp = new Employee();
    emp.setId(1);
    emp.setFirstName("Bill");
    emp.setLastName("Gates");
    emp.setIncome(100.0);

    Employee emp2 = new Employee();
    emp2.setId(2);
    emp2.setFirstName("Steve");
    emp2.setLastName("Job");
    emp2.setIncome(200.0);

    employees.getEmployees().add(emp);
    employees.getEmployees().add(emp2);
  }