title: Extract a value from XML response and set it as a global variable in Postman
body: <p>I am trying to extract a value from a successful API request, which is sending a XML response, using Postman. Following is the way how I tried to catch the value that I need from the response.</p>
  
  <pre><code>var jsonObject = xml2Json(responseBody);
  console.log(jsonObject);
  
  postman.setGlobalVariable("Active_SAML", jsonObject.bankidCollectResponse.SAMLReferens); 
  console.log(pm.globals.get("Active_SAML"));
  </code></pre>
  
  <p>That script written inside "Tests" tab and the console log out put is as below.</p>
  
  <p><a href="https://i.stack.imgur.com/tRG02.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tRG02.png" alt="enter image description here"></a></p>
  
  <p>But when I execute the program, I get following error.</p>
  
  <blockquote>
    <p>There was an error in evaluating the test script:  TypeError: Cannot
    read property 'SAMLReferens' of undefined</p>
  </blockquote>
  
  <p>I am not sure where I'm doing it wrong. Can anybody please point out me that?</p>