#!/bin/python # works w/Jython also import xml.dom.minidom as dom input_xml = """ username password 1.0 en urn:ietf:params:xml:ns:domain-1.0 urn:ietf:params:xml:ns:host-1.0 ABC-12345-XYZ """ """ Simple doctest: >>> fromprettyxml(input_xml) usernamepassword1.0enurn:ietf:params:xml:ns:domain-1.0urn:ietf:params:xml:ns:host-1.0ABC-12345-XYZ """ def fromprettyxml(input_xml): #cool name, but not the opposite of dom.toprettyxml() _dom = dom.parseString(input_xml) output_xml = ''.join([line.strip() for line in _dom.toxml().splitlines()]) _dom.unlink() return output_xml def _test(): import doctest, stripxml doctest.testmod(stripxml) if __name__ == "__main__": _test() print fromprettyxml(input_xml)