public static void main(String[] args) throws Exception {
ArrayList<StepAttributesDisplay> attrList = new ArrayList<StepAttributesDisplay>();
//Get the DOM Builder Factory
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
//Get the DOM Builder
DocumentBuilder builder = factory.newDocumentBuilder();
//Load and Parse the XML document
//document contains the complete XML as a Tree.
Document document =
builder.parse(
ClassLoader.getSystemResourceAsStream("xml/input.xml"));
// for now lets keep one object
//Iterating through the nodes and extracting the data.
NodeList nodeList = document.getDocumentElement().getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
StepAttributesDisplay attributesDisplay = new StepAttributesDisplay();
NodeList childNodes = node.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++) {
Node cNode = childNodes.item(j);
if (cNode instanceof Element) {
NodeList childNodes2 = cNode.getChildNodes();
for (int h = 0; h < childNodes2.getLength(); h++) {
Node dNode = childNodes2.item(h);
// System.out.println(cNode.getNodeName());
if (dNode.getNodeName().equals("function")) {
System.out.println(dNode.getLastChild().getNodeValue().trim());
attrList.add(attributesDisplay);
for (int x = 0; x < attrList.size(); x++) {
System.out.println("Function New " + attrList.get(x).getFunction());
}//attrList.add(attributesDisplay);
}
}
}
}
}
}
}
output that i get is :
0
Alloc
Alloc
Function New Alloc
Format
Format
Function New Format
Function New Format
Format Check
Format Check
Function New Format Check
Function New Format Check
Function New Format Check
Delete
Delete
Function New Delete
Function New Delete
Function New Delete
Function New Delete
4
0
FunctionDelete
1
FunctionDelete
2
FunctionDelete
3
FunctionDelete
Ideally it should be:
FunctionAlloc
FunctionFormat
FunctionFormat Check
FunctionDelete