DOM question - AttributeError: setAttribute

Asked by DeepBlade

Perhaps my python skills are fading away.. but I'm getting the error "AttributeError: setAttribute"

when I attempt to apply an attribute to a document object:

newDeviceHWID = xml.createDocument(None, "devicehwid", None)
newDeviceHWID.setAttribute("colour", "blue")

Can someone give me an example of how it should be done?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
DeepBlade
Solved:
Last query:
Last reply:
Revision history for this message
DeepBlade (deepblade) said :
#1

I am using minidom

Revision history for this message
RaiMan (raimund-hocke) said :
#2

setAttribute() is only defined for elements.
newDeviceHWID only contains the root element after creation: root = newDeviceHWID.documentElement

now you can append newly created elements:
body = newDeviceHWID.createElement("body")
root.appendChild(body)
body.setAttribute(...)

Revision history for this message
DeepBlade (deepblade) said :
#3

I need a DOM book. Thanks! =)