In previous post [1], we showed how to create a XMLDOM, of which the root
element is called html via xml.dom.minidom. In this post, we show how to add
a text node to the root element. Note that the text node is the leaf in the DOM
trees, which means the text node has no children node or element.
In line 10, we get the root element of the document DOM. In line 11, we create
a text node, and in line 12, we add the text node to the root element. Note that
the text node can be added to any element, not only to root element.
The following is the output:
<?xmlversion="1.0"?><html>HelloWorld!</html>
It's pretty easy and straight forward to manipulate the xml.dom.minidom
library. In the next post [3], we will show how to create an element and add it
to the DOM trees.