eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
311 stars 64 forks source link

Proper handling of namespace collision #4

Open boucman opened 10 years ago

boucman commented 10 years ago

I just had some problems with draw:frame and namspaces

this element can have both a presentation:style-name and a draw:style-name attribute. the current Element.setAttribute() function will use the first attribute with the name given (in this case draw:) but there is no easy way to access the other attribute. I had to use Element.setAttrNS which is undocumented and doesn't check the grammar

I looked in the api documentation and that sort of conflicts seem common enough that it needs to be dealt with...

I would suggest adding an optional "namespace= namspace.NAME" parameter to setAttribute, maybe make it mandatory for attributes that have a conflict...

bufke commented 10 years ago

Sorry for the delay on responding - this project desperately needs volunteers. Let us know if you can help.

boucman commented 10 years ago

i'll try to see what I can do, how would you prefer to have this handled ? documentation ? new function ? optional parameter ?

bufke commented 10 years ago

@sorenroug would be better to comment on this. All I have done so far on this project so far is put it back on pypi. If you propose your own solution I could help you test it out at least.

sorenroug commented 10 years ago

It is possible to deal with namespace collission. There is a qattributes argument that takes a namespace, localname tuple:

from odf import draw
from odf.namespaces import PRESENTATIONNS, DRAWNS
df = draw.Frame(width="476pt", height="404pt", 
      qattributes={  (PRESENTATIONNS, 'style-name'): 'presstyle',
      (DRAWNS, 'style-name'): 'drawstyle' } )
boucman commented 10 years ago

@sorenroug so a documentation patch would be enough in your view ? does that work with Element.setAttrbute too ?

sorenroug commented 10 years ago

Yes it does. If the attribute name is a tuple, like (PRESENTATIONNS, 'style-name').