Jibx mapping parent elements in child collection

rikaroo

New Member
Given the xml below:\[code\]<Book bookName='WCE6'><Trades> <Trade> <TradeIdentifier>466810212</TradeIdentifier> <riskMeasures> <VOL_GAMMA> <InstrumentIdType>TBD</InstrumentIdType> <InstrumentIdentifier>0987.BE</InstrumentIdentifier> <Value>9988</Value> </VOL_GAMMA> <EQ_GAMMA> <InstrumentIdType>RIC</InstrumentIdType> <InstrumentIdentifier>0397.BE</InstrumentIdentifier> <Value>1000</Value> </EQ_GAMMA> </riskMeasures> </Trade> <Trade> <TradeIdentifier>466810213</TradeIdentifier> <riskMeasures> <EQ_GAMMA> <InstrumentIdType>RIC</InstrumentIdType> <InstrumentIdentifier>EXEA.BE</InstrumentIdentifier> <Value>1000</Value> </EQ_GAMMA> </riskMeasures> </Trade> </Trades>\[/code\]I have created this jibx binding file (see below) to create a collection of 'Risk' objects. What I want to do is with each risk object is include the TradeIdentifier that comes from the parent trade, so essentially flattening the structure somewhat, to fit the Java properties below.\[code\] <binding name="risk"> <mapping name="Book" class="Book"> <value name="bookName" field="name" style="attribute"/> <structure name="Trades" allow-repeats="true" ordered="false"> <structure name="Trade" > <value name="TradeIdentifier" /> <collection name="riskMeasures" field="risks"> <structure name="EQ_GAMMA" type="Risk"> ********* I want to map the TradeIdentifier here *********** <value name="InstrumentIdType" field="instrumentIdType" style="element"/> <value name="InstrumentIdentifier" field="instrumentIdentifier" style="element"/> <value name="Value" field="value" style="element"/> </structure> </collection> </structure> </structure> </mapping> </binding> private String tradeIdentifier; private String instrumentIdType; private String instrumentIdentifier; private String value;\[/code\]I have tried many different things to map the TradeIdentifier into the child collection but to no avail. I have done this before with other marshallers so would hope that Jibx can do this easily. Can anyone provide an answer to this please?
 
Back
Top