Search code examples
xmlsoappretty-print

Save XML response to file with formatting


I am making a SOAP request to a webservice and are receiving an XML response. Currently I am saving this XML into a file which works fine, but the XML looks like a mess, no linebreaks and indents. See this example in one line:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SoegPersonRegistreringCprResponse xmlns="http://webservices.rki.dk/"><SoegPersonRegistreringCprResult><Error xmlns="http://webservices.rki.dk"><Code>101</Code><Text>Generel fejl</Text><Detailed>InternWS.Common.Exceptions.InternWSException: Generel fejl</Detailed></Error></SoegPersonRegistreringCprResult></SoegPersonRegistreringCprResponse></soap:Body></soap:Envelope>

In editor it looks like this: enter image description here

Is it possible to save this XML into file and keep the nice formatting like it has in browsers. See this example: enter image description here


Solution

  • If you're using Notepad++, you can use the XML Tools plugin to prettify your XML file.

    Note that the original file, without indents and line breaks, is still valid XML, even though it is less human-readable.