0

I am trying to extract a value within an ISO String which I get from a jPOS Structured Data. The string looks like this:

221ThirdPartyBillPayment3125
<ThirdPartyBillPayment>
    <BillPaymentRequest>
        <ReferenceId>1111111111</ReferenceId>
    </BillPaymentRequest>
</ThirdPartyBillPayment>

Is there a way I can get the value "1111111111" of ReferenceId node?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Sulaiman Adeeyo
  • 485
  • 6
  • 19

2 Answers2

1

The sample data is a postilion structured data field which uses kind of a TLV (tag length value format).

221ThirdPartyBillPayment3125
<ThirdPartyBillPayment>
    <BillPaymentRequest>
        <ReferenceId>1111111111</ReferenceId>
    </BillPaymentRequest>

221ThirdPartyBillPayment

Here 2 is the length of length (21), 21 is the length of the tag ThirdPartyBillPayment

3125
    <ThirdPartyBillPayment>
        <BillPaymentRequest>
            <ReferenceId>1111111111</ReferenceId>
        </BillPaymentRequest>
    </ThirdPartyBillPayment>

Here 3 is the length of length (125), 125, is the length of data to follow.

You could write code to get access to xml iteratively for all thats available in structured data and then parse out the xml data within. Or You could ask Postilion for the dtd/schema for the xml used in their structured data iso field and use jaxb to access the data.

It will boil down to a name value pair

ThirdPartyBillPayment= <ThirdPartyBillPayment><BillPaymentRequest<ReferenceId>1111111111</ReferenceId></BillPaymentRequest>
</ThirdPartyBillPayment>
chhil
  • 442
  • 4
  • 12
0

You've got some custom data in a mix of some fixed fields and some XML there, so you first need to get the whole field off your ISOMsg, i.e:

String s = m.getString("127.1"); // provided your data comes in field 127.1

Then figure out where the XML starts (in this case, at indexOf('<')), then you need feed that XML in an XML parser (you can use jdom that comes as a jPOS dependency), parse the XML and get the child element ReferenceId.

apr
  • 1,288
  • 7
  • 8