Roxy Roxy - 4 days ago 5
Bash Question

Curl Request : response using curl Request is not properly formatted(xml)

i am loading xml as String from Remote using curl as below:

$ curl -i -H "Accept: application/xml" -X GET "URL Here"


but response is not xml format, hence not easily readable.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><RunConfig <PipeLineXmlVersion>1.0</PipeLineXmlVersion><DateTime>20161128_160859</DateTime><Analysis><Lane>1</Lane><PipeLine>run_multiplexed_auto_start_v4.0.sh</PipeLine><Version>4.0</Version><Mismatch>1</Mismatch><MergeLane>0</MergeLane<Version>4.0</Version></Analysis></RunConfig>


When i try the same API using some REST client then i can see the proper xml.

As i searched, Accept header should work but unfortunately not in my case.

Please help me with this.

Thanks.

Answer

If what you mean by "not proper" is the fact that the response is not pretty printed (i.e. lack spaces and indent), there are plenty of command line tools to format xml.

For example:

curl ... | xmllint --format -

Here, you pass the response of curl to xmllint (part of xmllib2-utils), which will format your answer. The - in the end tells the tool to print the result in the console.

Have a look at this question for more ways to achieve it.

Comments