I need to update specific items in a database. These items can be found from the database by using the ID-value found from the XML-file.
The XML-file is something like this:
<Employees>
<Employee>
<id>123</id>
<age>29</age>
<role>Java Developer</role>
<gender>Male</gender>
</Employee>
<Employee>
<id>234</id>
<age>35</age>
<role>CSS Developer</role>
<gender>Female</gender>
</Employee>
</Employees>
Is it possible to gather the IDs to an array, then loop the array through an sql update method? Is looping an sql query method bad practise or is there another way?
Also can this be done without XML parsers such as DOM, SAX or JAXB to keep it simple?
EDIT1
This is my solution for extracting ID values from XML without using XML parsers:
public static void main(String[] args) throws Exception {
try {
File fXmlFile = new File("employee.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
Document doc = (Document) dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList employeeIdNodeList=doc.getElementsByTagName("id");
for(int k=0;k<employeeIdNodeList.getLength();k++) {
Node employeeIdNode = (Node) employeeIdNodeList.item(k);
System.out.println(employeeIdNode.getTextContent());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Any thoughts? Is it efficient? It is based on XML Parse for specific element in java. There will be max 10 employees in the XML.