Giovanni Cappellotto <potoma...@gmail.com> added the comment:

I took a quick look at `minidom.py` and `test_minidom.py`. It seems that you 
should always use `doc.renameNode(attr, namespace, new_name)` for renaming an 
attribute (or an element).

When `doc.renameNode` is applied on an attribute node, it removes the attribute 
from the `ownerElement` and re-set it after renaming it.

For instance:

```
>>> import xml.dom.minidom
>>> from xml.dom import minidom
>>> doc = minidom.parseString("<a href=\"http://foo.com\";>foo</a>")
>>> attr = doc.childNodes[0].attributes.item(0)
>>> doc.renameNode(attr, xml.dom.EMPTY_NAMESPACE, "bar")
<xml.dom.minidom.Attr object at 0x7fb27d7ddb00>
>>> doc.toxml()
'<?xml version="1.0" ?><a bar="http://foo.com";>foo</a>'
```

I agree that this behavior should be documented somewhere.

Maybe there should be a note/warning in the `name` attribute description. It 
should says that resetting an attribute `name` won't change the document 
representation and that `doc.renameNode` should be used instead.

Another approach may be to update the `name` setter implementation to remove 
and then re-set the attribute in the `ownerElement`.

What do you think it's the best approach:

1. update the doc
2. update the `name` setter implementation

I'd be happy to help to fix this issue.

----------
nosy: +potomak

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue13127>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to