minidom question from a newbie

antonmuhin на rambler.ru antonmuhin at rambler.ru
Wed Jan 29 17:08:24 CET 2003


Hello henk,

Wednesday, January 29, 2003, 5:24:18 PM, you wrote:

import xml.dom.minidom

data = {
    "First category" : ["a", "b"],
    "Second category" : ["c"]
}

def buildDoc(data):
    doc = xml.dom.minidom.Document()
    part = doc.createElement("PredefinedTexts")
    for name, lines in data.items():
        cat = doc.createElement("Category")
        cat.setAttribute("name", name)
        for line in lines:
            text = doc.createElement("Text")
            text.setAttribute("text", line)
            cat.appendChild(text)
            
        part.appendChild(cat)
        
    doc.appendChild(part)
    return doc

file(r"sample.xml", 'w').write(buildDoc(data).toprettyxml())

    
-- 
Best regards,
 anton                            mailto:antonmuhin at rambler.ru






More information about the Python-list mailing list