Hi,
I got a xml string as the json response body from the third party API.When I call the API.It;s response is json format.
{
"referenceId": "b7e0fdacd8bd",
"profileId": "PC12345678",
"statusCode": "ACCP",
"statusDesc": "Account transactions report generated successfully.",
"reportBase64": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCEtLSBTYW1wbGUgWE1MIGZpbGUgZ2VuZXJhdGVkIGJ5IEZGRlMgKHd3dy5ma2wuZmkpIEIyQyBwcm9qZWN0IGZvciBGSW5uaXNoIEFjY291bnQgUmVwb3J0LCAyMDA5LTExLTAyLCBmb3IgZGlmZmVyZW50IEVudHJ5IGluc3RhbmNlIGZvciAtLT4KPCEtLSBNVDIxMCAvIFByZW5vdGljZSBvZiBpbmNvbWluZyBpbnRlciBuYXRpb25hbCB0cmFuc2FjdGlvbiAod2l0aG91dCBiYWxhbmNlcykgYW5kIG9uZSBzaW1wbGUgaW50cmEgZGF5IGJhbGFuY2UgcmVwb3J0IHdpdGggb25lIHRyYW5zYWN0aW9uLS0
}
reportBase64 has the encoded string.When I decode it ,It showed a xml string like below.
?xml version="1.0" encoding="UTF-8"?>
<!-- Sample XML file generated by FFFS (www.fkl.fi) B2C project for FInnish Account Report, 2009-11-02, for different Entry instance for -->
<!-- MT210 / Prenotice of incoming inter national transaction (without balances) and one simple intra day balance report with one transaction-->
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.052.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:camt.052.001.02
camt.052.001.02.xsd">
<BkToCstmrAcctRpt>
<GrpHdr>
<MsgId>BANKFILEID219073</MsgId>
<CreDtTm>2009-10-30T12:01:45+02:00</CreDtTm>
<MsgRcpt>
<Id>
<OrgId>
<Othr>
<Id>123456789</Id>
<SchmeNm>
<Cd>BANK</Cd>
</SchmeNm>
</Othr>
</OrgId>
</Id>
</MsgRcpt>
<AddtlInf>Some additional message-specific info can be delivered from bank to customer here</AddtlInf>
</GrpHdr>
</BkToCstmrAcctRpt>
</Document>
I need to get the above MsgId xml element from above xml string.
I used the below query to extract element from xml.
var myDetails = JsonConvert.DeserializeObject<MyDetail>(responseJson.ToString());
byte[] mybyte = System.Convert.FromBase64String(myDetails.reportBase64);
string returntext = System.Text.Encoding.UTF8.GetString(mybyte);
order.OrderDesc = myDetails.statusDesc;
PXTrace.WriteInformation(returntext);
Base.Document.Update(order);
//xml read
string data = returntext;
XElement elem = XElement.Parse(data);
var test = elem.Element("BkToCstmrAcctRpt").Element("GrpHdr").Element("MsgId").Value;
if(test!=null){
PXTrace.WriteInformation(test);
}
But,It showed a null reference error in the trace.
Best answer by praveenpo
View original