# Parse XML response to get a value

**URL:** <https://community.postman.com/t/parse-xml-response-to-get-a-value/40593>\
**Category:** Help Hub\
**Tags:** parse, xml-response\
**Created:** [October 29, 2022, 12:12pm UTC](https://community.postman.com/t/parse-xml-response-to-get-a-value/40593 "2022-10-29T12:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tibornagy](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tibornagy](https://community.postman.com/u/tibornagy)\
**Post date:** [October 29, 2022, 12:12pm UTC](https://community.postman.com/t/parse-xml-response-to-get-a-value/40593/1 "2022-10-29T12:12:00Z")

</div>

Hi guys,

I have a POST request and get the following response in XML:

```auto
<feed xmlns="http://www.w3.org/2005/Atom">
    <link href="https://xyz?page=1&pagesize=50" rel="self" />
    <link href="https://xyz/biprws/v1/cmsquery?page=1&pagesize=50" rel="first" />
    <link href="https://xyz/biprws/v1/cmsquery?page=1&pagesize=50" rel="last" />
    <entry>
        <content type="application/xml">
            <attrs xmlns="http://www.sap.com/rws/bip">
                <attr name="SI_ID" type="integer">302155</attr>
                <attr name="SI_NAME" type="string">TEXT</attr>
            </attrs>
        </content>
    </entry>
</feed>

```

I would like to parse this response (in Tests script) to get the “SI\_ID” value 302155:

console.log(xml2Json(pm.response.text()));

I get “Undefined” error message.

Thanks,  
Tibor

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [October 29, 2022, 5:12pm UTC](https://community.postman.com/t/parse-xml-response-to-get-a-value/40593/2 "2022-10-29T17:12:45Z")

</div>

Hi @tibornagy

I was playing around with this and noticed it doesn’t like parsing the href links as XML. If you remove them it works.

Are you in control of the response body? … If so you could change it to this;

```auto
<feed xmlns="http://www.w3.org/2005/Atom">
    <![CDATA[
        <link href="https://xyz?page=1&pagesize=50" rel="self" />
        <link href="https://xyz/biprws/v1/cmsquery?page=1&pagesize=50" rel="first" />
        <link href="https://xyz/biprws/v1/cmsquery?page=1&pagesize=50" rel="last" />
    ]]>
    <entry>
        <content type="application/xml">
            <attrs xmlns="http://www.sap.com/rws/bip">
                <attr name="SI_ID" type="integer">302155</attr>
                <attr name="SI_NAME" type="string">TEXT</attr>
            </attrs>
        </content>
    </entry>
</feed>

```

If you are not in control of the response body, you could parse as text and use a RegEx to pull out the value you want, like this;

```auto
const response = pm.response.text();
console.log(response);

let formatMatch = new RegExp("<attr name=\"SI_ID\" type=\"integer\">(.*?)</attr>").exec(response);

pm.test("Validate id value", function () {
    pm.expect(formatMatch, "Format does not match regular expression.").to.not.eql(null);
    console.log("formatMatch = " + formatMatch[1]);
});

```

---

<div class="post-metadata">

**Author:** ![tibornagy](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@tibornagy](https://community.postman.com/u/tibornagy)\
**Post date:** [October 31, 2022, 11:50am UTC](https://community.postman.com/t/parse-xml-response-to-get-a-value/40593/3 "2022-10-31T11:50:32Z")

</div>

Yes it looks like that I cant parse the response body because of those href links. I cant control the response body. The RegExp is a good idea but would be easier the xml2Json stuff.  
Thanks for the answer
