// BEGIN USER CODE
try
{
//creating a constructor of file class and parsing an XML file
File file = new File("F:\\XMLFile.xml");
//an instance of factory that gives a document builder
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//an instance of builder to parse the specified xml file
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName("student");
// nodeList is not iterable, so we are using for loop
for (int itr = 0; itr < nodeList.getLength(); itr++)
{
Node node = nodeList.item(itr);
System.out.println("\nNode Name :" + node.getNodeName());
if (node.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) node;
//Your Action
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
// END USER CODE
Directly after the XML-import add the activity rollback.
If you have multiple objects that got created, rollback each of them.