Need to get (Key,Value) from XML based on previous element (Key,Value) data

Can't Post

Based on the below sample xml, I need to write a perl script which will fetch all ‘TOTALAMOUNT’ value, however I also need to put a condition on previous element key ‘INVOICEDATE’ based on which ‘TOTALAMOUNT’ can be retrived.

First, the INVOICE elements need to be wrapped in a root element, or the XML will not be well-formed.

Once that's done, the following code will do the job.

A couple of comments: to parse a file you will need to replace the call to parse by parsefile, your numbers are formatted the "European" way (with a comma before the decimal part), which is not the way Perl likes its numbers, so you need to convert them. Making the code robust is left as an exercise to the reader, since I can't really make assumptions about what is likely to go wrong with the data.