Actually I have a raw data which will have the information about scan rejected files. Each rejected item will log info. in 3 elements in raw data i.e i)ScanRejected ii) ScanInitiated iii) CardSupplier. I'm trying to process this raw data and put it in XML in a formatted way. While processing each record every time if I find <ScanRejected> element then I want to access <CardSupplier> element to get the CardNumber. it means I need to access ONLY immediate previous CardSupplier element.
Here in this case I need to get card number as
<CardNumber t="String">##############0251</CardNumber> NOT <CardNumber t="String">##############1111</CardNumber>
INPUT:
<ScanRejected>
<Validity t="String">NotValidated</Validity>
<EventID t="String">ScanRejected</EventID>
</ScanRejected>
<ScanInitiated>
<EventID t="String">ScanInitiated</EventID>
<TransactionReference t="String"></TransactionReference>
</ScanInitiated>
<CardSupplier>
<CardNumber t="String">##############0251</CardNumber>
<CardPosition t="String">Inserted</CardPosition>
<CardValid t="Boolean">True</CardValid>
<EventID t="String">CardAccepted</EventID>
</CardSupplier>
<ScanRejected>
<Validity t="String">NotSupported</Validity>
<EventID t="String">ScanRejected</EventID>
</ScanRejected>
<ScanInitiated>
<EventID t="String">ScanInitiated</EventID>
<TransactionReference t="String"></TransactionReference>
</ScanInitiated>
<CardSupplier>
<CardNumber t="String">##############1111</CardNumber>
<CardPosition t="String">Inserted</CardPosition>
<CardValid t="Boolean">True</CardValid>
<EventID t="String">CardAccepted</EventID>
</CardSupplier>
<ScanRejected>
<Validity t="String">NotScanned</Validity>
<EventID t="String">ScanRejected</EventID>
</ScanRejected>
<ScanInitiated>
<EventID t="String">ScanInitiated</EventID>
<TransactionReference t="String"></TransactionReference>
</ScanInitiated>
<CardSupplier>
<CardNumber t="String">##############2345</CardNumber>
<CardPosition t="String">Inserted</CardPosition>
<CardValid t="Boolean">True</CardValid>
<EventID t="String">CardAccepted</EventID>
</CardSupplier>- OUTPUT:
-<Tran>
<TranName>ScanRejected</TranName>
<CardNumber>##############0251</CardNumber>
</Tran>
-<Tran>
<TranName>ScanRejected</TranName>
<CardNumber>##############1111</CardNumber>
</Tran>
-<Tran>
<TranName>ScanRejected</TranName>
<CardNumber>##############2345</CardNumber>
</Tran>