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?
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>
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.
Related
This is very new to me. I am reading data from a cassandra table. This data is being extracted via a "select json * ..." query but here's the thing. The format of that json is
{"acct_ref_nb": 1401040701, "txn_pst_dt": "2020-02-26", "txn_pst_tm": 1934131, "txn_am": 15000.0 ....
Every field is in quotation marks, followed by a colon, followed by the value, then a comma and the next field, so on and so forth.
We need to reformat this and have a nested structure. We also need to change the names of the fields. So you would have something like...
"{
"ccEvent": {
"account": {
"accountReferenceNumber": 1401040701,
"transactionPostDate": "2020-02-26",
"transactionPostTime": 1934131,
"transactionAmount": 15000.0,
........
Is there a preferred library to do this? I'm literally lost even at a high level on how to do this. Thanks.
In Java I parse a XML document. This XML is a Purchase Order and from this XML I create a PO document in our ERP-system.
I use domparser to parse the XML.
So eventually I have code like this:
--this is an excerpt --
//ShipTo
Element shipToElement = CXMLHandlerObj.getChildElement(elementOrderRequestHeader, "ShipTo");
//Address
Element shipToAddressElement = CXMLHandlerObj.getChildElement(shipToElement, "Address");
/*get attributes of Address*/
notesHandlerObj.docOrder.replaceItemValue("ShipToParty_addressID", shipToAddressElement.getAttribute("addressID"));
notesHandlerObj.docOrder.replaceItemValue("ShipToParty_addressIDDomain", shipToAddressElement.getAttribute("addressIDDomain"));
notesHandlerObj.docOrder.replaceItemValue("ShipToParty_isoCountryCode", shipToAddressElement.getAttribute("isoCountryCode"));
But the XML also contains at the top a OrderRequestHeader which has a type attribute in it:
<OrderRequestHeader orderDate="2017-04-04T12:00:00+00:00" orderID="4550144777" orderType="regular" orderVersion="1" type="new">
Below this element all the details of the order are found.
The "type" attribute can have values like : New or Update.
The type will be "new" if the PO XML is send for the first time and the type will be "update" if the same PO is sent but then with an update contained within it.
Note that the XML structure is the same but only the type is different.
When the type is "New", I will just parse the XML and create the PO document. But if the type is "Update" then I want to check every element and update the document and mail the changes accordingly..
Now the problem is that for the parsing of the XML I need to create a new PO or update an existing one. This I can do by the following ways:
1. creating two methods :
1. create new PO
2. update PO
In the create method I can parse the xml and add values from element to the document.
In the update method I can parse again all elements but also check which data has been changed.
2. I can put a if and else statement before every element
The methods of above are a bit redudant is there any simpler way of doing this?
I'm trying to convert an xml to json data using the java-json.jar . The conversion is done. but have issues with the resulting JSON data like
An Integer is expected but the data is converted as String.
it would not create a list if there was only one child element ( even when it should be a list as per the JSON schema ).
Is there any way to convert XML into JSON based on the JSON schema in Java?
We have a requirement of parsing xml data in java.
The xml data looks like this:
xml_data
1> The first question here is how to parse such data.I have tried the code suggested in this link :
xmlparse with Node
and have partial success. The only doubt here is how can i can to reach "" tag.
2>The second question is if the data is parsed how can we can store the values in single object,so that we can get length and values of "CRAWL", "Test", "Check"(Tables) separately(from single object)?
Please help me as how can we achieve this?
Abhi
I m doing parse from xml to Java object. Here is the xml example:
<weather_data>
<date>today</date>
<weather>shower</weather>
<date>tomorrow</date>
<weather>snow</weather>
</weather_data>
That is to say, there are same elements like date and weather inside one weather_data
if I use createOnElement="weather_data/date", I can only get the last date value.
What should I do.
Thanks