先上代码: #!/usr/bin/env python3 # _*_ coding: utf-8 _*_ from xml.dom.minidom import Document def readFile(filename, lines): with open(filename, 'r') as f: for line in f: line = line.rstrip(' \n') if line.startswith('//') or len(line) == 0: continue line
单纯的为DOM树添加结点. #!/usr/bin/env python # Generating XML with DOM - Chapter 8 - domgensample.py from xml.dom import minidom, Node doc = minidom.Document() doc.appendChild(doc.createComment("Sample XML Document - Chapter 8 -")) # Generate book book =