Hi I have these classes right here: As you can see Faculty and Student inherits name from Persons. And faculty and student all have their unique attributes with that as well
public class Persons{
protected String name;
public Persons(){
this(null);
}
public Persons(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public String setName(String name){
this.name = name;
}
}
public class Student extends Persons{
private String studentId;
public Student(){
this(null,null);
}
public Student(String name,String studentId){
this.name = name;
this.studentId = studentId;
}
}
public class Faculty extends Persons{
private String facultyId;
public Faculty(){
this(null,null);
}
public Faculty(String name,String facultyId){
this.name = name;
this.facultyId = facultyId;
}
}
Provided that I have these XML files:
<persons>
<student>
<name>Example 1</name>
<studentid>id</studentid>
</student>
<student>
<name>Example 1</name>
<studentid>id</studentid>
</student>
</persons>
and the Faculty XML file:
<persons>
<faculty>
<name>Example 1</name>
<facultyid>id</facultyid>
</faculty>
<faculty>
<name>Example 1</name>
<facultyid>id</facultyid>
</faculty>
</persons>
how would I set up the classes for unmarshalling from the xml files. I have done this with normal xml files where there is not inheritance, but I was just wondering how would I do this without writing the same attributes in two classes. Thank You!
No comments:
Post a Comment