mimidom: setting a value of an attribute
Martin v. Loewis
martin at v.loewis.de
Thu Aug 1 17:21:43 EDT 2002
Michael Grabietz <michael.grabietz at img-online.de> writes:
> # create an attribute
> a1 = doc.createAttributeNS(None,u'attrib')
This is a namespace operation.
> # add it under the sect1 element
> # Now I want to set the value 'attvalue' to the previously added
> attribute a1
> # The following fails !
This is not. This is the first error - you should not mix NS and
non-NS operations (they do interoperate to some level, but you really
need to decide whether you want to make a namespace-aware or a
The real problem, however, is that you misunderstand the signature of
setAttribute: it expects the attribute name and attribute value, see
So proper usage would be (leaving namespaces aside):
That saves you creating the attribut node explicitly. If you want to
use the attribute node, you should do
a1.nodeValue = 'attvalue'
More information about the Python-list