How can I remove the whitespaces and line breaks in an XML string in Python 2.6? I tried the following packages:
etree: This snippet keeps the original whitespaces:<
A little clumsy solution without lxml :-)
data = """ """ data3 = [] data2 = data.split('\n') for x in data2: y = x.strip() if y: data3.append(y) data4 = ''.join(data3) data5 = data4.replace(" ","").replace("> <","><") print data5 Output: