1

I have a list of grades inside a list of students. I want to save it into a xml file. Anyone knows how can I obtain a xml file like that, is it possible using JavaXB?

<students>
        <student>
            <firstName>Hans</firstName>
            <lastName>Muster</lastName>
            <grades>
                   <grade>
                         <value>10</value>
                   </grade>
                   <grade>
                         <value>9</value>
                   </grade>
                   <grade>
                         <value>8</value>
                   </grade>
                   <grade>
                         <value>10</value>
                   </grade>
        </student>
        <student>
            <firstName>Ruth</firstName>
            <lastName>Mueller</lastName>
            <grades>
                   <grade>
                         <value>7</value>
                   </grade>
                   <grade>
                         <value>4</value>
                   </grade>
                   <grade>
                         <value>8</value>
                   </grade>
                   <grade>
                         <value>11</value>
                   </grade>
        </student>
    </students>

This is my class:

public class Student {
    private final StringProperty firstName;
    private final StringProperty lastName;
    private final ListProperty<Integer> grades;
    public Client() {
        ObservableList<Integer> gradess = FXCollections.observableArrayList();
        grades=new SimpleListProperty<Integer>(gradess);
        this.firstName = new SimpleStringProperty(firstName);
        this.lastName = new SimpleStringProperty(lastName);
}
}

This is my ClassWrapper

@XmlRootElement(name = "students")
public class StudentWrapper {

    private List<Student> students;

    @XmlElement(name = "students")
    public List<Student> getStudents() {
        return clients;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }
}
  • Yes, it is possible with JAXB. There is an example here: http://stackoverflow.com/questions/3683598/jaxb-how-to-marshal-objects-in-lists – Bajal Apr 02 '16 at 01:16

0 Answers0