fork download
  1. from xml.etree.cElementTree import XMLParser
  2.  
  3. def parse_multiple(lines):
  4. for line in lines:
  5. parser = XMLParser()
  6. parser.feed("<root>") # start of xml document
  7. while line.strip(): # while non-blank line
  8. parser.feed(line) # continue xml document
  9. line = next(lines, "") # get next line
  10. parser.feed("</root>") # end of xml document
  11. yield parser.close() # yield root Element of the xml tree
  12.  
  13.  
  14. import sys
  15. import xml.etree.cElementTree as etree
  16.  
  17. for root in parse_multiple(sys.stdin):
  18. etree.dump(root)
Success #stdin #stdout 0.11s 9344KB
stdin
<a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c></c></d>

<a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c></c></d>

<a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c></c></d>
stdout
<root><a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c /></d>
</root>
<root><a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c /></d>
</root>
<root><a>
    <b>
       ....
    </b>
    <c>
       ....
    </c>
</a>
<d><c /></d></root>