I have an XML file
<Entry>
<uid>11111</uid>
<firstName>Alex</firstName>
<lastName>Stoun</lastName>
<sdnType>Individual</sdnType>
<idList>
<id>
<uid>2233</uid>
</id>
</idList>
<akaList>
<aka>
<uid>3333</uid>
<lastName>Stounne</lastName>
<firstName>Aliks</firstName>
</aka>
</akaList>
</Entry>
Not all data from the XML file must get into the table.
The table has columns:
id | uid | fullName | sdnType | alias
@Override
public void parseSnFile(String fileName) {
//...
try {
//...
NodeList list = doc.getElementsByTagName("Entry");
List<someEntity> entity = new ArrayList<>();
for (int temp = 0; temp < list.getLength(); temp++) {
Node node = list.item(temp);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String id = element.getElementsByTagName("uid").item(0).getTextContent();
String lastName = element.getElementsByTagName("lastName").item(0).getTextContent();
String firstName = element.getElementsByTagName("firstName").item(0).getTextContent();
String sdnType = element.getElementsByTagName("sdnType").item(0).getTextContent();
String programList = element.getElementsByTagName("program").item(0).getTextContent();
MyEntity entity = new MyEntity(id, lastName, snType, program); //serealize your data into entity
myRepo.save(entity) //saving to database
System.out.println(id + " " + lastName + " snType " + snType + " programList " + programList);
someEntity entity = new someEntity(Long.parseLong(uid), firstName + lastName, *** );
entity.add(someEntity);
}
}
repository.saveAll(entity);
At this point I need to add alias data (in the XML file, these are firstName
and lastName
, which are inside the <akaList>
tag)
Perhaps this can be done through a for loop, but I don’t know how to add this element to my table. There are more than 1000 entries in the XML file, and inside the <Entry>
tag is the <akaList>
tag. Both the <Entry>
tag and the <akaList>
tag have lastName
and firstName
.
How do I get this data to be written to different columns?