/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
from xml.dom import minidom #doc = minidom.parse(file) doc = minidom.parseString("<a>hello</a>") print doc.toprettyxml(encoding="utf-8") node=doc.createElement("b") node.setAttribute("nom","val") doc.documentElement.appendChild(node) node2=doc.createTextNode("koko") doc.documentElement.appendChild(node2) print doc.toprettyxml(encoding="utf-8") for i in doc.documentElement.childNodes: print i,i.nodeType #(i.ELEMENT_NODE,i.TEXT_NODE) for i in doc.getElementsByTagName("a"): print "-<A>-",i node.parentNode.removeChild(node) node2.parentNode.removeChild(node2) print doc.toprettyxml(encoding="utf-8")