我有一份学生名单中的成绩列表。我想将其保存到xml文件中。任何人都知道如何获得这样的xml文件,是否可以使用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>
这是我的班级:
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);
}
}
这是我的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;
}
}