I receive from Webservice the following XML:
<ns1:irsValorationReturn xmlns:ns1="http://webServices.es">
<ns1:error xsi:nil="true"/>
<ns1:format>dd/MM/yyyy</ns1:format>
<ns1:pricingDate>02/09/2013</ns1:pricingDate>
<ns1:results>
<ns1:items>
<ns1:bpv>-395.79435433174876</ns1:bpv>
<ns1:npv>26960.051401523993</ns1:npv>
<ns1:payingNpv>0.0</ns1:payingNpv>
<ns1:pricingDelta>342.85778485967523</ns1:pricingDelta>
<ns1:receivingNpv>26960.051401523993</ns1:receivingNpv>
<ns1:swapRate>0.6811631117640043</ns1:swapRate>
</ns1:items>
</ns1:results>
</ns1:irsValorationReturn>
I need to transform this XML into a HashMap. The entries of HashMap must be variables depending on the value between keys {} ({KEY OF HASHMAP}) from the template below. The value of the corresponding key in Hashmap would be the original value from the WebService XML response, i.e.
BPV = -395.79435433174876;
NPV = 26960.051401523993
...
<ns1:irsValorationReturn xmlns:ns1="http://webServices.es">
<ns1:error xsi:nil="true"/>
<ns1:format></ns1:format>
<ns1:pricingDate><ns1:pricingDate>
<ns1:results>
<ns1:items>
<ns1:bpv>{BPV}</ns1:bpv>
<ns1:npv>{NPV}</ns1:npv>
<ns1:payingNpv>{PAYING_NPV}</ns1:payingNpv>
<ns1:pricingDelta>{PRICING_DELTA}</ns1:pricingDelta>
<ns1:receivingNpv>{RECEIVING_NPV}</ns1:receivingNpv>
<ns1:swapRate>{SWAP_RATE}</ns1:swapRate>
</ns1:items>
</ns1:results>
</ns1:irsValorationReturn>
If I change {NPV} for {NPV_NEW} the resulting HashMap should be:
BPV = -395.79435433174876;
NPV_NEW = 26960.051401523993
I thought in parse template XML and when you find a tag with a value that matches with pattern {.+} search through the original XML for that tag. Then you put the entry in Hashmap with the key of the template XML and the value of the original XML.
Has any better way? I think it can be a little inefficient parsing original XML each time I find a node with variable value.