def parse_xml_buffer(buffer):
    dom = minidom.parseString(''.join(buffer))
buffer = [file.readline()]
for line in file:
    if line.startswith('<?xml '):
        parse_xml_buffer(buffer)
buffer = []
buffer.append(line)
parse_xml_buffer(buffer)
Python to parse non-standard XML file