Splitting a DOM
Brice Vissi?re
brice.vissiere at costes-gestion.net
Thu Feb 12 10:59:21 EST 2004
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.reader import Sax2
from xml.dom.ext import PrettyPrint
reader = Sax2.Reader()
my_dom = reader.fromUri('steps.xml')
steps = my_dom.getElementsByTagName('STEP')
i=0
for step in steps:
tmp = file('step%s.xml' % i,'w')
tmp.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
PrettyPrint(step , 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
More information about the Python-list
mailing list