tags:

views:

74

answers:

2

Hi, I have two file. I have to modify the file one in a particular node and add in a list of child. The list is in the file2. Can I do it, and how?

from xml.dom.minidom import Document from xml.dom import minidom
file1=modificare.xml file2=sorgente.xml

xmldoc=minidom.parse(file1)

for Node in xmldoc.getElementsByTagName("Sampler"): # put in the file2 content

Thanks a lot.

+2  A: 

use ElementTree:

from xml.etree.ElementTree import Element, SubElement, Comment, tostring

# Configure one attribute with set()
root = Element('opml')
root.set('version', '1.0')

root.append(Comment('Generated by ElementTree_csv_to_xml.py for PyMOTW'))

http://broadcast.oreilly.com/2010/03/pymotw-creating-xml-documents.html

shavenwarthog
A: 

I haven't understand. I have two file. file1 is an xml that contain the code to modify. file2 contain some element that I have to add in file2.

How I can do this?

Thanks.

michele