Hello,
I would like to handle an XML file structured as following
<ROOT>
<STEP>
....
</STEP>
<STEP>
....
</STEP>
....
</ROOT>
From this file, I want to build an XML file for each STEP block.
Currently I'm doing something like:
from xml.dom.ext.rea der import Sax2
from xml.dom.ext import PrettyPrint
reader = Sax2.Reader()
my_dom = reader.fromUri( 'steps.xml')
steps = my_dom.getEleme ntsByTagName('S TEP')
i=0
for step in steps:
tmp = file('step%s.xm l' % i,'w')
tmp.write('<?xm l version="1.0" encoding="ISO-8859-1" ?>\n')
PrettyPrint(ste p , tmp , encoding='ISO-8859-1')
tmp.close()
i+=1
But I'm pretty sure that there's a better way to split the DOM ?
Thanks for any suggestion provided.
Brice
I would like to handle an XML file structured as following
<ROOT>
<STEP>
....
</STEP>
<STEP>
....
</STEP>
....
</ROOT>
From this file, I want to build an XML file for each STEP block.
Currently I'm doing something like:
from xml.dom.ext.rea der import Sax2
from xml.dom.ext import PrettyPrint
reader = Sax2.Reader()
my_dom = reader.fromUri( 'steps.xml')
steps = my_dom.getEleme ntsByTagName('S TEP')
i=0
for step in steps:
tmp = file('step%s.xm l' % i,'w')
tmp.write('<?xm l version="1.0" encoding="ISO-8859-1" ?>\n')
PrettyPrint(ste p , tmp , encoding='ISO-8859-1')
tmp.close()
i+=1
But I'm pretty sure that there's a better way to split the DOM ?
Thanks for any suggestion provided.
Brice
Comment