I would like to comment on a specific XML element in an XML file. I could just delete the item, but I would prefer to leave it commented, if necessary later.
The code that I use at the time of deleting the item is as follows:
from xml.dom import minidom doc = minidom.parse(myXmlFile) for element in doc.getElementsByTagName('MyElementName'): if element.getAttribute('name') in ['AttribName1', 'AttribName2']: element.parentNode.removeChild(element) f = open(myXmlFile, "w") f.write(doc.toxml()) f.close()
I would like to change this so that he comments on the element, rather than deleting it.
source share