[XML-SIG] elementtree, element.text = value problem and a couple other questions

Werner F. Bruhin werner.bruhin at free.fr
Mon Dec 19 14:13:29 CET 2005

I just don't get it.

Excerpt from my code:

def addElement(doc, name):
    new = et.SubElement(doc, name)
    return new

def addValueElement(doc, name, value):
    new = et.SubElement(doc, name)
    new.text = value
    new.text = '\n'
    return new

doc_header = """<wine></wine>"""
doc = et.XML(doc_header)
addValueElement(xml, u'name', string.strip(dbItem.winename))
addValueElement(xml, u'additionalname', string.strip(dbItem.winename2))
.... more

But the "value" writing to new.text doesn't show up in the xml file.


What am I missing?

By the way is it possible to write the file in a "pretty" format?

One last question (at least for the moment) is how to get something 
along the following lines into the header/beginning of the file:
<?xml version="1.0" encoding="UTF-8"?>
<?jaxfront version=1.60;time=2005-12-18 12:15:07.078;xsd=wineXML.xsd?>
<wine xmlns="http://www.winexml.org/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

I added it to my "doc_header" variable but I can't get it to write 
exactly this.


More information about the XML-SIG mailing list