You could use Simple form simple XML serialization:
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
public class App {
public static void main(String[] args) throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<table sourceName=\"person\" targetName=\"person\">\n"
+ " <column sourceName=\"id\" targetName=\"id\"/>\n"
+ " <column sourceName=\"name\" targetName=\"name\"/>``\n"
+ "</table>";
Serializer serializer = new Persister();
Table table = serializer.read(Table.class, xml);
System.out.println(table.getSourceName());
System.out.println(table.getTargetName());
for (Column colunmn : table.getColumns()) {
System.out.println(colunmn.getSourceName());
System.out.println(colunmn.getTargetName());
}
}
}
Table:
import java.util.List;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root(name = "table")
public class Table {
@Attribute
private String sourceName;
@Attribute
private String targetName;
@ElementList(name = "column", inline = true)
private List<Column> columns;
public Table() {
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public String getTargetName() {
return targetName;
}
public void setTargetName(String targetName) {
this.targetName = targetName;
}
public List<Column> getColumns() {
return columns;
}
public void setColumns(List<Column> columns) {
this.columns = columns;
}
}
Column:
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
@Root(name = "column")
public class Column {
@Attribute
private String sourceName;
@Attribute
private String targetName;
public Column() {
}
public String getSourceName() {
return sourceName;
}
public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
public String getTargetName() {
return targetName;
}
public void setTargetName(String targetName) {
this.targetName = targetName;
}
}