Hello,
I have an error “assignment in conditional expression” that I tried Googling for hours last night and hope I can get some help.
I am trying to get the nonce out of an XML response. Below is the original responseBody.
Response Body:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="link"><soapenv:Body><processOCIMessageResponse xmlns="urn:com:broadsoft:webservice" xmlns:ns="urn:com:broadsoft:webservice"><processOCIMessageReturn><?xml version="1.0" encoding="ISO-8859-1"?><BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="link"><sessionId xmlns="">33</sessionId><command echo="" xsi:type="AuthenticationResponse" xmlns=""><userId>bryankowalczyk</userId><nonce>1557585660073</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></BroadsoftDocument></processOCIMessageReturn></processOCIMessageResponse></soapenv:Body></soapenv:Envelope>
Even after performing xm2json in the Postman, I don’t get a properly formatted JSON converting the XML to key:value pairs. It still remains a string
<?xml version="1.0" encoding="ISO-8859-1"?> <BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="link"><sessionId xmlns="">33</sessionId><command echo="" xsi:type="AuthenticationResponse" xmlns=""><userId>bryankowalczyk</userId><nonce>1557585660073</nonce><passwordAlgorithm>MD5</passwordAlgorithm></command></BroadsoftDocument>
I tried using a regex to extract the nonce which does work successfully using Node outside of Postman but I get an error “assignment in conditional expression” in Postman when trying to execute it.
The code I am using in the tests section in Postman is as follows:
var responseJson = xml2Json(responseBody);
console.log(responseJson);
var re = new RegExp("<nonce>(.*?)</nonce?>", "gmi");
while (res = re.exec(responseBody)){ console.log(res[1])}
It struggles with the ‘while’ command. Any thoughts on how I can extract this value cleanly?
I appreciate it!
P.S. I had to remove ‘http’ from the XML as I am limited to links I can post.