As I saw, when we run
from xml.dom.minidom import parse
myXML = parse('anything.xml')
in a Python script, it loads the contents of “anything.xml”, until you leave the script or Ctrl+D your Python session.
Is it possible to add attribute values to this loaded version of the XML in Python?
The
parsemethod returns you an instance ofxml.dom.minidom.Document, on which you can invoke the plethora of methods listed in the documentation ofxml.dom. Here’s a small example:This adds a
joe="2"attribute to theheadtag: