Hi i am trying to parse a large xml file and printing the tags to a output file. I am using minidom, my code is working fine for 30Mb files but more than that its getting memory error.So i used buffer reading the file but unable to get the desired output.
XML File
<File>
<TV>Sony</TV>
<FOOD>Burger</FOOD>
<PHONE>Apple</PHONE>
</File>
<File>
<TV>Samsung</TV>
<FOOD>Pizza</FOOD>
<PHONE>HTC</PHONE>
</File>
Desired Output
Sony,Burger,Apple
Samsung,Pizza,HTC
When reading in buffer its giving me an output say :-
*Sony,Bur
Samsung,Pizza,HT*
code:
while 1:
content = File.read(2048)
if not len(content):
break
for lines in StringIO(content):
lines = lines.lstrip(' ')
if lines.startswith("<TV>"):
TV = lines.strip("<TV>")
tvVal = TV.split("</TV>")[0]
#print tvVal
w2.writelines(str(tvVal)+",")
elif lines.startswith("<FOOD>"):
FOOD = lines.strip("<FOOD>")
foodVal = FOOD.split("</FOOD>")[0]
#print foodVal
w2.writelines(str(foodVal)+",")
............................
...........................
I am trying with seek() but still if the buffer is reading till Bur i am not able to get the desired output. Thanks in advance