This is an academic assignment and we are given an extremely large XML file with hundreds of entries like these. For each item we are supposed to list the Manager's ID, the Person's ID of the last person to add an item to the list, and the current number of items. I have read and reread the Oracle DOM API and various Node APIs. We are using JAVA and I cannot for the life of me figure out how to search various 'fields' of each item_list
node. Below is an example of the data we are given.
<item_list id="item_list01">
<numitems_intial>5</numitems_initial>
<item>
<date_added>1/1/2014</date_added>
<added_by person="person01" />
</item>
<item>
<date_added>1/6/2014</date_added>
<added_by person="person05" />
</item>
<numitems_current>7</numitems_current>
<manager person="person48" />
</item_list>
<item_list id="item_list02">
<numitems_intial>5</numitems_initial>
<item>
<date_added>1/15/2014</date_added>
<added_by person="person05" />
</item>
<item>
<date_added>1/1/2014</date_added>
<added_by person="person09" />
</item>
<item>
<date_added>1/9/2014</date_added>
<added_by person="person45" />
</item>
<numitems_current>7</numitems_current>
<manager person="person38" />
</item_list>
I've tried doing something similar to:
NodeList nodes = queryDoc.getElementsByTagName("item_list");
for(int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if(node != null) {
System.out.println(node.manager);
}
}
And messing around with this code for a while, but I would like to know how to retrieve data from various fields in each node.