lxml.etree fromsting() and tostring() are not returning the same data
问题 I'm learning lxml (after using ElementTree) and I'm baffled why .fromstring and .tostring do not appear to be reversible. Here's my example: import lxml.etree as ET f = open('somefile.xml','r') data = f.read() tree_in = ET.fromstring(data) tree_out = ET.tostring(tree_in) f2 = open('samefile.xml','w') f2.write(tree_out) f2.close 'somefile.xml' was 132 KB. 'samefile.xml' - the output - was 113 KB, and it is missing the end of the file at some arbirtrary point. The closing tags of the overall