Remove whitespaces in XML string
The easiest solution is probably using lxml, where you can set a parser option to ignore white space between elements: >>> from lxml import etree >>> parser = etree.XMLParser(remove_blank_text=True) >>> xml_str=””‘<root> >>> <head></head> >>> <content></content> >>> </root>”’ >>> elem = etree.XML(xml_str, parser=parser) >>> print etree.tostring(elem) <root><head/><content/></root> This will probably be enough for your needs, but … Read more