I have this code for reading XML files:
try {
File fXmlFile = new File(fullFilePath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("task");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
int i = temp;
MyTasks.customers[i][11] = getTagValue("att1", eElement);
MyTasks.customers[i][12] = getTagValue("att8", eElement);
MyTasks.customers[i][13] = getTagValue("att2", eElement);
MyTasks.customers[i][14] = getTagValue("att7", eElement);
MyTasks.customers[i][15] = getTagValue("att3", eElement);
MyTasks.customers[i][16] = getTagValue("att4", eElement);
MyTasks.customers[i][18] = getTagValue("att5", eElement);
MyTasks.customers[i][19] = getTagValue("att6", eElement);
//ect
}
}
} catch (Exception e) {
CreateLog.addToLog("[ReadXML]" + e.toString());
}
Is it possible to continue reading the XML file after an error occurs. If one attribute does not exists the whole script stops reading and catchs an error.
Thanks in advance
It is possible. Add a
try-catchstatement inside thefor-loopand in case of catching an exception just use thecontinue;statement.