made xml writing incremental to handle large files