0

我正在尝试在从 jPOS 结构化数据获得的 ISO 字符串中提取一个值。字符串如下所示:

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

有没有办法获得 ReferenceId 节点的值“1111111111”?

4

2 回答 2

1

样本数据是使用一种 TLV(标签长度值格式)的 postilion 结构化数据字段。

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

221ThirdPartyBillPayment

这里2是length(21)的长度,21是标签ThirdPartyBillPayment的长度

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

这里3是length(125)的长度,125是后面数据的长度。

您可以编写代码以迭代地访问结构化数据中所有可用的 xml,然后解析出其中的 xml 数据。或者,您可以向 Postilion 询问结构化数据 iso 字段中使用的 xml 的 dtd/schema,并使用 jaxb 访问数据。

它将归结为一个名称值对

ThirdPartyBillPayment= <ThirdPartyBillPayment><BillPaymentRequest<ReferenceId>1111111111</ReferenceId></BillPaymentRequest>
</ThirdPartyBillPayment>
于 2016-08-18T04:34:07.773 回答
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.

于 2015-05-29T16:00:10.150 回答