actually minidom is no more difficult to use than other dom parsers, if you
dont like it you may want to consider complaining to the w3c
from xml.dom.minidom import parseStringXML = """<nodeA> <nodeB>Text hello</nodeB> <nodeC><noText></noText></nodeC></nodeA>"""def replaceText(node, newText): if node.firstChild.nodeType != node.TEXT_NODE: raise Exception("node does not contain text") node.firstChild.replaceWholeText(newText)def main(): doc = parseString(XML) node = doc.getElementsByTagName('nodeB')[0] replaceText(node, "Hello World") print doc.toxml() try: node = doc.getElementsByTagName('nodeC')[0] replaceText(node, "Hello World") except: print "error"if __name__ == '__main__': main()


