使用格式化将XML响应保存到文件

时间:2015-07-29 19:34:14

标签: xml soap pretty-print

我正在向Web服务发出SOAP请求,并且正在接收XML响应。目前我将这个XML保存到一个工作正常的文件中,但XML看起来像一团糟,没有换行符和缩进。 请在一行中查看此示例:

<?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>

在编辑器中,它看起来像这样:enter image description here

是否可以将此XML保存到文件中并保持其在浏览器中的良好格式。请参阅此示例:enter image description here

1 个答案:

答案 0 :(得分:1)

如果您正在使用Notepad ++,则可以使用XML Tools插件来美化您的XML文件。

请注意,没有缩进和换行符的原始文件仍然是有效的 XML,即使它不易被人类阅读。

相关问题