Using java, I’m trying to find the most recent highest entry number. This entry needs to specify a specific type. From there it needs to pull the value.
Here’s what the xml looks like
<XmlFile>
<data_item>
<data_report>
<type>My_Type</type>
<entry_number>12</entry_number>
<value>1234</value>
</data_report>
<data_report>
<type>My_Type</type>
<entry_number>9</entry_number>
<value>11234</value>
</data_report>
</data_item>
<data_item>
<data_report>
<type>My_Type</type>
<entry_number>17</entry_number>
<value>112354</value>
</data_report>
<data_report>
<type>Not_My_Type</type>
<entry_number>122</entry_number>
<value>11234</value>
</data_report>
</data_item>
</XmlFile>
So the takeaways are the data I need needs to be of “My_Type” it can be in ANY data_item, but it needs to find the maximum interval out of all items of my_type, the pull the value only.
I have tried doing this with Xpath, but I couldn’t quite get it to work. In this case the third data report (in the second data item) would be the one I’m after since it has the highest entry number while being “My Type” so I would want the program to grab the number 112354 for me.
Is there some way to do this using Xpath? The file that I’m trying to get this to work on is MUCH larger than this, but Xpath seems like the easiest option, I’m not opposed to DOM or SAX if those are better suited.
Thanks!
The
max()function is not available in XPath 1.0.A pure XPath expression that produces the wanted (of the first if there are more than one nodes with the wanted maximum property) value, is:
XSLT – based verification:
when this transformation is applied on the provided XML document:
the XPath expression is evaluated and the result of this evaluation is copied to the output: