From bcdf194baeb349fe69480e1e9a152ba8bdbfbc73 Mon Sep 17 00:00:00 2001 From: Rav Chandra Date: Wed, 16 Oct 2013 12:33:19 +1300 Subject: [PATCH] process XML data before pretty-printing to trim whitespace --- httpie/output.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/httpie/output.py b/httpie/output.py index 0f0d93c7..56bc69d6 100644 --- a/httpie/output.py +++ b/httpie/output.py @@ -409,8 +409,10 @@ class XMLProcessor(BaseProcessor): def process_body(self, content, content_type, subtype, encoding): if subtype == 'xml': try: - # Pretty print the XML - doc = xml.dom.minidom.parseString(content.encode(encoding)) + # Pretty print the XML; pre-process content into clean string + raw_string = ''.join( + (x.strip() for x in content.encode(encoding).split('\n'))) + doc = xml.dom.minidom.parseString(raw_string) content = doc.toprettyxml(indent=' ' * DEFAULT_INDENT) except xml.parsers.expat.ExpatError: # Ignore invalid XML errors (skips attempting to pretty print)