Message346582
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. |
|
Date |
User |
Action |
Args |
2019-06-26 03:51:49 | potomak | set | recipients:
+ potomak, terry.reedy, scoder, ezio.melotti, docs@python, dillona, urjitsb87, cheryl.sabella, epicfaace |
2019-06-26 03:51:49 | potomak | set | messageid: <1561521109.19.0.73619285844.issue13127@roundup.psfhosted.org> |
2019-06-26 03:51:49 | potomak | link | issue13127 messages |
2019-06-26 03:51:48 | potomak | create | |
|