mimidom: setting a value of an attribute

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


Hi,

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
art.appendChild(s1)

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

# add it under the sect1 element
s1.setAttributeNode(a1)

# Now I want to set the value 'attvalue' to the previously added 
attribute a1
# The following fails !
s1.setAttribute(a1,'attvalue')

----------------------------------------------------------------


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


Regards,

Michael










More information about the Python-list mailing list