How to parse xml within CDATA inside XML host response?

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?

Unfortunately I don’t manage to write here the content of CDATA so I can only paste it as image


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                &lt;HostResponse Attr6="0000" ATTRIBUTE7="00039208052" Versione="2.0"&gt;
                    &lt;Header Attr8="XYZ" Attr9="0101010001001000192" Attr1="CD23" Timestamp="20200513184508520"/&gt;

                    &lt;Result Attr10="25838" ExDate="20220331" Attr11="000100031408"/&gt;

In Tests there is:
var responseJson = xml2Json(responseBody);

and the Output in the console is:
{VASMessage: {…}}

  1. VASMessage: {…}
  2. $: {…}
    1. xmlns: “
  3. Header: {…}
    HeadElem1: “SIA0101010001001”
    HeadElem2: “192”
    OriginalTime: “2020-05-13T17:21:00.000+02:00”
    TransactionCode: “70”
    ReqProcessing: “false”
    MessageType: “false”
    MessageDirection: “true”
    AeviResponseCode: “0”
  4. 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: "

Have you tried paring that part with xml2Json, something like:


Hi @vdespa,

many thanks for help.
I’ve tried but it doesn’t resolve the problem.

var responseJson = xml2Json(responseBody.Body.VASDataString);

the result is:
“TypeError: Cannot read property ‘VASDataString’ of undefined”

Thank you :wink:

Hi @alberto.bura,

I would use the xml2js module as xml2Json is included as part of the legacy sandbox API. Try something like this:

const xml2js = require('xml2js');
xml2js.parseString(pm.response.text(), (err, result) => {
    if (err) {

    const body = result.VASMessage.Body[0].VASDataString[0];
    xml2js.parseString(body, (err, result) => {
        if (err) {

Related: XML response escape characters



1 Like

I have presented a general idea on how to approach this. You need to make sure that the path to the property is correct.

Thank you so much!
It worked like charm.
I actually looked at XML response escape characters but it was beyond my knowledge.
Thank you again.

1 Like