Author potomak
Recipients cheryl.sabella, dillona, docs@python, epicfaace, ezio.melotti, potomak, scoder, terry.reedy, urjitsb87
Date 2019-06-26.03:51:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561521109.19.0.73619285844.issue13127@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-06-26 03:51:49potomaksetrecipients: + potomak, terry.reedy, scoder, ezio.melotti, docs@python, dillona, urjitsb87, cheryl.sabella, epicfaace
2019-06-26 03:51:49potomaksetmessageid: <1561521109.19.0.73619285844.issue13127@roundup.psfhosted.org>
2019-06-26 03:51:49potomaklinkissue13127 messages
2019-06-26 03:51:48potomakcreate