Hi everyone,
I’ve read multiple resources here and elsewhere, but I failed to resolve my problem.
I send a POST request in XML to a host having CDATA made of another XML “request”, and the response has the same structure.
From the nested XML response inside CDATA I need to extract an attribute (‘ATTRIBUTE7’) that will be an environment variable.
My understanding is that due to CDATA the content of VASDataString is seen as a block of text that shall not be parsed.
How can I overtake this block?
Request:
Unfortunately I don’t manage to write here the content of CDATA so I can only paste it as image
Response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Header>
<HeadElem1>ABC123</HeadElem1>
<HeadElem2>192</HeadElem2>
<OriginalTime>2020-05-13T17:21:00.000+02:00</OriginalTime>
<TransactionCode>70</TransactionCode>
<ReqProcessing>false</ReqProcessing>
<MessageType>false</MessageType>
<MessageDirection>true</MessageDirection>
<ResponseCode>0</ResponseCode>
</Header>
<Body>
<VASProviderID>ABC</VASProviderID>
<VASProductID>PIPPO</VASProductID>
<VASMessageType>PIPPO_RESPONSE</VASMessageType>
<TransactionTime>2020-05-13T17:21:00.000+02:00</TransactionTime>
<RetailerID>0101</RetailerID>
<BranchID>01</BranchID>
<ShopID>0001</ShopID>
<POSID>001</POSID>
<VASDataString><HostMessage>
<PIPPO_RESPONSE>
<HostResponse Attr6="0000" ATTRIBUTE7="00039208052" Versione="2.0">
<Header Attr8="XYZ" Attr9="0101010001001000192" Attr1="CD23" Timestamp="20200513184508520"/>
<Result Attr10="25838" ExDate="20220331" Attr11="000100031408"/>
</HostResponse>
</PIPPO_RESPONSE>
</HostMessage></VASDataString>
</Body>
In Tests there is:
var responseJson = xml2Json(responseBody);
console.log(responseJson);
and the Output in the console is:
{VASMessage: {…}}
- VASMessage: {…}
- $: {…}
1. xmlns: “http://subdomain.domain.com” - Header: {…}
HeadElem1: “SIA0101010001001”
HeadElem2: “192”
OriginalTime: “2020-05-13T17:21:00.000+02:00”
TransactionCode: “70”
ReqProcessing: “false”
MessageType: “false”
MessageDirection: “true”
AeviResponseCode: “0” - Body: {…}
VASProviderID: “ABC”
VASProductID: “PIPPO”
VASMessageType: “PIPPO_RESPONSE”
TransactionTime: “2020-05-13T17:21:00.000+02:00”
RetailerID: “0101”
BranchID: “01”
ShopID: “0001”
POSID: “001”
VASDataString: "