Display XML response

Hello
Can anyone help me to solve this issue ?


I use all solution to diplay < in place of &lt but it does not work

Hey @hendaderbali :wave:

Welcome to the Postman Community! :postman:

How are you planning on using the modified response body?

In your code you have pm.response.text(modifiedResponseBody), which isn’t the correct syntax as that function doesn’t take an argument.

If you could provide more context and information, it will be easier to help you out here. :pray:

i am using c data xml request ,
but response does not contains ‘<’ int return this ‘&lt’ and this ‘&#xD’ ;

You can’t edit the response like you can with the request using pre-request scripts and pm.request.body.

It’s static\read only. The response is what the API returned, you can’t edit it.

You can parse the response to text() or use the cheerio library.

Your replace command should work (but if not, there are dozens of topics on the subject if you search the interweb). Postman uses JavaScript in the tests tab, so you just need to include that in your search.

At which point, you can console log the updated parsed response (but you can’t change the actual response).

As Danny mentioned. What are you trying to do with this?

“&lt” is the escaped version of “<”.

Just i want to keep my response but displayed with <> and not &lt

I appreciate that, but unless you can get your API to return the response without escaped characters, then this isn’t going to work.

On a side note, what does the response start with? Is it a string (with the whole response wrapped in quotes)?

this is the begin of request :slight_smile:

And this is the begin of REsponse :

What are the response headers that are returned?

Are you manually setting that content type as XML because Auto isn’t picking up the correct content type header?

@danny-dainton

If the content headers are correct, are we expecting the pretty print to automatically format the special characters?

I was wondering if the whole XML was wrapped in a string, but it appears to be ok.

My thinking was about seeing the response headers, was around noticing the content type had been manually changed in the response pane.

It could be a red herring but it caught my eye and I was wondering why that needed to be changed :thinking:

so it is impossible to change it ??

Any script that you create in the Tests section is executed after the response is received from the server - It’s not going to change anything you see in the response pane.

I still don’t really know what you are expecting to see in the UI, as a result of running a script. I believe that part of your question is still unclear.

Using this API as an example of returning XML, just to show it doesn’t happen on every API:

https://random-data-api.com/api/v2/users?size=2&is_xml=true&response_type=xml

Do you see the same encoding if you call the service using cURL from the command line?

I’m assuming at this point (perhaps incorrectly) that its the API that is sending it back escaped.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.