XML : How to add an attribute to a tag found using xpath in lxml in Python?

I have the following xml -

  <draw:image></draw:image>    

I want to add multiple xlink attributes to it and make it -

  <draw:image xlink:href="image" xlink:show="embed"></draw:image>    

I tried using the following code but got the error "ValueError: Invalid attribute name u'xlink:href'"

  root.xpath("//draw:image", namespaces=  {"draw":"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"})  [0].attrib['xlink:href'] = 'image'    

What am I doing wrong? There seems to be something related to namespaces, but I can't figure what.

No comments:

Post a Comment