from xml.dom import minidomStation1 = ['Pentium M', '512MB']Station2 = ['Pentium Core 2', '1024MB']Station3 = ['Pentium Core Duo', '1024MB']StationList = [Station1, Station2, Station3]DOMimpl = minidom.getDOMImplementation()xmldoc = DOMimpl.createDocument(None,"Workstations", None)doc_root = xmldoc.documentElementfor station in StationList: #Create Node node = xmldoc.createElement("Computer") element = xmldoc.createElement('Processor') element.appendChild(xmldoc.createTextNode(station[0])) node.appendChild(element) element = xmldoc.createElement('Memory') element.appendChild(xmldoc.createTextNode(station[1])) node.appendChild(element) doc_root.appendChild(node)nodeList = doc_root.childNodesfor node in nodeList: print node.toprettyxml()file = open("stations.xml", 'w')file.write(xmldoc.toxml())
Name (required)
email (will not be published) (required)
Website