2

I would like to map the totalAmt tag in below xml file, both its value 100 and it's attribute Ccy.

<?xml version="1.0" encoding="UTF-8"?>
<transaction>
   <id>
       <eId>transactionId001</eId>
   </id>
   <amount>
       <totalAmt Ccy="XXX">100</totalAmt>
   </amount>
</transaction>

By reading BeanIO reference guide and posts here I got the impression that only one of them can be mapped.

So my question is: Can BeanIO handle this tag and could you show me how?

What I have tried and didn't work:

<segment name="amount">
    <field name="totalAmount" xmlName="totalAmt"></field>
    <field name="currency" xmlName="Ccy" xmlType="attribute"></field>
</segment>
Lucky
  • 16,787
  • 19
  • 117
  • 151
sarahTheButterFly
  • 1,894
  • 3
  • 22
  • 36

2 Answers2

3

Close, but you still need to add the segment element inside the segment tag to tell which field the attribute is belong to.

example.

<segment name="amount">
    <field name="totalAmount" xmlName="totalAmt"></field>
    <segment name="totalAmt">
        <field name="type" xmlName="Ccy" xmlType="attribute"></field>
    </segment>
</segment>
kucing_terbang
  • 4,991
  • 2
  • 22
  • 28
  • It works! Something is wrong with my account, I can't upvote and choose this answer. It keeps saying something wrong with your request, try agin. Any body has ideas why? – sarahTheButterFly Sep 07 '15 at 23:17
  • good for you ;). Well, probably some error on SO. try logout, remove all cache and then try again – kucing_terbang Sep 08 '15 at 03:10
0

I am using bean io 2.1 version The

<segment name="totalAmt">
    <field name="totalAmount" xmlType="text"></field>  --->the bean variable "totalAmount" will give say 100 
    <field name="Cctype" xmlName="Ccy" xmlType="attribute" default="XXX"></field>    -->either set default value as XXX or it will take from cctype variable
</segment>