mimidom: setting a value of an attribute

Michael Grabietz michael.grabietz at img-online.de
Thu Aug 1 22:30:43 CEST 2002


I experimente with the XML-DOM for Python. I understand after studying 
examples provided in a tutorial how to set elements and the content of 
elements. Now I want to create and set attributes and I fail.

See the code below:

# create a new document
doc = parseString( u'<article/>'. encode('UTF-8'))
art = doc.documentElement

# create a sect1 element
s1 = doc.createElementNS(None,u'sect1')

# add it under the root element

# create an attribute
a1 = doc.createAttributeNS(None,u'attrib')

# add it under the sect1 element

# Now I want to set the value 'attvalue' to the previously added 
attribute a1
# The following fails !


Probably there is somebody, who could help a freshman on XML with Python.



More information about the Python-list mailing list