views:

50

answers:

1

Hi, I have two xml file: 1)model.xml 2)projectionParametersTemplate.xml

I want to extract from 1) Algorithm Node with his child and put it in 2)

I have wrote this code but it doesn't function.

from xml.dom.minidom import Document
from xml.dom import minidom      
xmlmodel=minidom.parse("/home/michele/Scrivania/d/model.xml")
xmltemplate=minidom.parse("/home/michele/Scrivania/d/projectionParametersTemplate.xml")

for Node in xmlmodel.getElementsByTagName("Algorithm"):
     print "\nNode: "+str(Node)
     for Node2 in xmltemplate.getElementsByTagName("ProjectionParameters"):
          print "\nNode2: "+str(Node2)
          Node2.appendChild(Node)

This is model.xml link text

This is projectionParametersTemplate.xml link text

Thanks a lot.

A: 

For me it works, e.g. the algorithm-node from xmlmodel is added to the ProjectionParameters-node from xmltemplate.

My guess is that you want to change the actual file. With your code, only the object in memory is modified, not the file on disk. If you want to change the file, add this line at the end:

xmltemplate.writexml(file("PATH_TO_OUTPUT_FILE.xml","w"))

P.S.: Maybe you get more answers when you improve your accept rate.

Daniel Hepper
Thank you!!!!!!
michele