RosettaCodeData/Task/XML-DOM-serialization/Python/xml-dom-serialization-1.py

13 lines
385 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
from xml.dom.minidom import getDOMImplementation
dom = getDOMImplementation()
document = dom.createDocument(None, "root", None)
topElement = document.documentElement
firstElement = document.createElement("element")
topElement.appendChild(firstElement)
textNode = document.createTextNode("Some text here")
firstElement.appendChild(textNode)
xmlString = document.toprettyxml(" " * 4)