This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: instantiating and populating xml.dom.minidom.Element is cumbersome
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Alexandre.Zani, avono, exarkun, hugovk, jesstess, mikecmcleod
Priority: normal Keywords: easy, needs review, patch

Created on 2009-01-05 19:08 by exarkun, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
easier_element_init.patch Alexandre.Zani, 2012-06-02 05:00 Add new optional arguments to Element constructor and tests review
issue4849.patch jesstess, 2014-03-09 21:27 review
issue4849_2.patch jesstess, 2014-03-11 18:15 s/assertEquals/assertEqual/g review
Messages (11)
msg79183 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-01-05 19:08
In order to create an element with an attribute and a child, this is
necessary:

    e = Element("foo")
    e.setAttribute("bar", "baz")
    e.appendChild(quux)

It would be preferable if Element.__init__ accepted two additional
parameters to shorten this:

    e = Element("foo", attributes={"bar": "baz"}, children=[quux])

It may also be preferable to have a third new parameter, attributesNS,
to parallel the Element.setAttributeNS method.  This would accept a dict
mapping namespaceURI and qualifiedName to an attribute value.
msg108192 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-06-19 18:11
As you Jean-Paul Calderone seem to know what you're talking about could you provide a patch to get this issue going?  If not I might even have a go myself, even if I do get shot down in flames.
msg111724 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-27 20:19
I think this could be sneaked into 3.2 if needed, but is it more work than the benefits actually deliver in the real world?
msg161577 - (view) Author: Alexander O (avono) Date: 2012-05-25 12:07
stupid question but why shouldn't this be possible ? 

class Element(_Element):
	def __init__(self,name,**kwargs):
		_Element.__init__(self,name)
                attributes = kwargs.get("attributes")
                children = kwargs.get("children")
		for key,value in attributes.iteritems():
			self.setAttribute(key,value)
		for child in children:
			self.appendChild(child)
msg162080 - (view) Author: Alexandre Zani (Alexandre.Zani) Date: 2012-06-01 17:11
I would tend to disagree with the use of **kwargs. It means the argument list would be implicit, not documented by the code and not checked at runtime. We could end up with anything in there. I'll try to propose a patch tonight that implements Jean-Paul's solution.
msg162123 - (view) Author: Alexandre Zani (Alexandre.Zani) Date: 2012-06-02 05:00
Here is my patch for it.
msg162341 - (view) Author: Alexander O (avono) Date: 2012-06-05 13:47
On Jun 2, 2012 7:00 AM, "Alexandre Zani" <report@bugs.python.org> wrote:

>
> Alexandre Zani <alexandre.zani@gmail.com> added the comment:
>
> Here is my patch for it.
>
> ----------
> keywords: +patch
> Added file: http://bugs.python.org/file25796/easier_element_init.patch
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue4849>
> _______________________________________
>
msg212986 - (view) Author: Jessica McKellar (jesstess) * (Python triager) Date: 2014-03-09 21:23
Thanks for the patch, Alexandre.Zani!
msg212987 - (view) Author: Jessica McKellar (jesstess) * (Python triager) Date: 2014-03-09 21:27
Sorry, stray submit, one more time:

Thanks for the patch, Alexandre.Zani!

Your patch had some whitespace issues according to `make patchcheck` (see http://docs.python.org/devguide/patch.html#generation for details).

I've uploaded a trivial update to your patch that passes patchcheck. The patch applies cleanly and test_minidom passes.

This enhancement may need some documentation on the new constructor before getting merged, but let's get a design review going.

=> patch review
msg409141 - (view) Author: mike mcleod (mikecmcleod) * Date: 2021-12-24 13:01
I would like to help with this issue. I'm new to this space hence I am not aware of what patch review means.
msg409521 - (view) Author: Hugo van Kemenade (hugovk) * (Python triager) Date: 2022-01-02 20:29
Hi Mike, "patch review" means:

"A patch or pull request exists, but it needs review. Any triager or core developer may do the review."

https://devguide.python.org/triaging/#stage

So we were waiting for someone to review patches listed above under the "Files" section (eg. issue4849_2.patch).

But seeing as they're from 2012/2014, and development has now moved to GitHub, a pull request needs to be opened on GitHub instead.

So I reckon you're good to go ahead and create a PR.
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49099
2022-01-02 20:29:55hugovksetnosy: + hugovk
messages: + msg409521
2021-12-24 13:01:05mikecmcleodsetnosy: + mikecmcleod
messages: + msg409141
2014-03-11 18:15:41jesstesssetfiles: + issue4849_2.patch
2014-03-09 21:27:32jesstesssetfiles: + issue4849.patch

messages: + msg212987
stage: needs patch -> patch review
2014-03-09 21:23:02jesstesssetversions: + Python 3.5, - Python 3.3
nosy: + jesstess

messages: + msg212986

keywords: + needs review
2014-02-03 19:11:40BreamoreBoysetnosy: - BreamoreBoy
2012-06-05 13:47:43avonosetmessages: + msg162341
2012-06-02 05:00:46Alexandre.Zanisetfiles: + easier_element_init.patch
keywords: + patch
messages: + msg162123
2012-06-01 17:11:33Alexandre.Zanisetmessages: + msg162080
2012-05-25 12:07:43avonosetnosy: + avono
messages: + msg161577
2012-05-21 06:23:58eric.araujosetkeywords: + easy
versions: + Python 3.3, - Python 3.2
2012-05-21 03:25:40Alexandre.Zanisetnosy: + Alexandre.Zani
2010-07-27 20:19:10BreamoreBoysettype: behavior -> enhancement
stage: needs patch
messages: + msg111724
versions: + Python 3.2
2010-06-19 18:11:02BreamoreBoysetnosy: + BreamoreBoy
messages: + msg108192
2009-01-05 19:08:25exarkuncreate