I am trying to insert xml nodes in this document:
</providers>
</root>
I wrote this code:
import xml.dom.minidom as m
doc = m.parse("monfichier.xml")
valeurs = doc.getElementsByTagName("providers")
element = doc.createElement("provider")
valeurs.appendChild(element)
elthost = doc.createElement("hostnamep")
eltLTVC = doc.createElement("LocalTrustValueC")
element.appendchild(elthost)
element.appendchild(eltLTVC)
texteHost = doc.createTextNode("machinename")
texteLTVC = doc.createTextNode("23")
eltHost.appendChild(texteHost)
eltLTVC.appendChild(texteLTVC)
doc.writexml(open("monfichier.xml","w"))
And I want to obtain at the end this xml document :
machinename
23
</provider>
</providers>
</root>
But I obtained this error :
valeurs.appendChild(element)
AttributeError: ‘NodeList’ object has no attribute ‘appendChild’
Based on some quick reading of http://docs.python.org/library/xml.dom.html#dom-node-objects it appears that NodeList does not have an appendChild method. Instead you want to get the first Node in the result set(since your post implies there is only one) and call appendChild on that node.