Here is a sample xml file that I am trying to pull data from:
<rss>
<channel>
<item>
<title>First Title</title>
<description>description text</description>
<component>Distribution - Maintain</component>
<timeoriginalestimate seconds="3600">1 hour</timeoriginalestimate>
<timespent seconds="1860">31 minutes</timespent>
</item>
<item>
<title>Second Title</title>
<description>description text</description>
<component>Reporting - Security</component>
<timeoriginalestimate seconds="3600">1 hour</timeoriginalestimate>
<timespent seconds="1860">31 minutes</timespent>
</item>
<item>
<title>third Title</title>
<description>description text</description>
<timeoriginalestimate seconds="5400">1 hour, 30 Minutes</timeoriginalestimate>
<timespent seconds="2700">45 minutes</timespent>
</item>
<item>
<title>Fourth Title</title>
<description>description text</description>
<component>Usability</component>
</item>
<item>
<title>Fifth Title</title>
<description>description text</description>
<component>Distribution - Maintain</component>
<timeoriginalestimate seconds="3600">1 hour</timeoriginalestimate>
<timespent seconds="7200">2 hours</timespent>
</item>
</channel>
</rss>
I want to collect the timeoriginalestimate
and timespent
nodes by component
value. I want to store the value of the component
into either a map or a hash as the key and then the value to be the total difference of timeoriginalestimate
and timespent
K = "Distribution - Maintain" V = 2hours-2hours31minutes
Some of the item
's will not have a component
and some of the component
's will not have the time values. In this case I would like to have the time values just added to the running total for an "other" component.
I am writing this in java and I am planning on printing out a report that will show how much time was estimated versus how much time was actually spent by each component. I'm not sure how to go about this.
Any help would be much appreciated. Thanks!
Sample code to count occurrences of a value:
private XPath featureXPath = XPath.newInstance("count(//rss/channel/item/type[text()='New Feature'])");
LinkedHashMap<String, Double> metrics = new LinkedHashMap<String, Double>();
metrics.put("New Features", (Double)featureXPath.selectSingleNode(doc));
I'm just not sure how I can add the time values to an unknown key and only add the time values for that their respective key