Splitting a DOM

Brice Vissi?re brice.vissiere at costes-gestion.net
Thu Feb 12 16:59:21 CET 2004


I would like to handle an XML file structured as following

>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')

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')

But I'm pretty sure that there's a better way to split the DOM ?

Thanks for any suggestion provided.


More information about the Python-list mailing list