Processing Two XML Files

Stuart Bishop zen at shangri-la.dropbear.id.au
Wed Feb 12 18:23:49 EST 2003


If you just want well formed XML and the character set encoding of the 
template
and data files are the same:
	xml = '<?xml version="1.0" encoding="whatever"?><group>%s%s</group>' % 
(
		open('template.xml').read(),open('zonebased.xml').read()
         )

If the character sets of the documents are not the same, you can use 
Python
XML tools to fix that.

Once you have a single document, use DOM, SAX, XSLT or whatever to do 
the
transformation you need.

An other alternative in this case would be to load both documents into
to DOM trees (using something like xml.minidom), and traverse the 'data'
tree using it to change the values in the 'template' tree. Use the XML
pretty printer on the modified 'template' tree for your result.

Check out the articles by Uche Ogbuji on xml.com 
(http://www.xml.com/pub/au/84),
especially 'Introducing PyXML'.
-- 
Stuart Bishop <zen at shangri-la.dropbear.id.au>
http://shangri-la.dropbear.id.au/






More information about the Python-list mailing list