From my simple XML below, I want to create an instance of SomeApplication with a collection of Field instances where each Field instance to represent a child element of <some-application>. The Field instances would have two String properties, name and value which are assigned from the node name and node value respectively.
XML input:
<some-application>
<field1>foo</field1>
<field2>bar</field2>
</some-application>
Java types:
public class Field {
private String name;
private String value;
public Field(String name, String value) {
this.name = name;
this.value = value;
}
public String getName(){
return name;
}
public String getValue(){
return value;
}
}
public class SomeApplication {
private List<Field> fields;
public SomeApplication(){
fields = new ArrayList<Field>();
}
public void addField(Field field){
fields.add(field);
}
}
What would be the best strategy for converting field elements (children of <some-application>) to Field instances?
Please note that I've simplified the requirement for the sake of brevity.
Thanks in advance.