Stefan Behnel schrieb am 13.02.2015 um 10:58:
Holger Joukl schrieb am 13.02.2015 um 10:38:
Would it help if the ElementMaker (a.k.a. E-factory) aggregated the namespace declarations of the children it receives? I don't think this is worth changing the way Elements work overall, but changing the ElementMaker sounds doable and reasonable to me.
Did the OP actually use the E-factory for tree assembly? Or you probably mean one should then use it to combine nodes to assemble, if aggregation is desired.
Yes. Although I guess that most data would already be passed through cleanup_namespaces() anyway when this comes up as an issue, so that might be the 'cleaner' canonical solution.
Maybe a convenience helper like cleanup_namespaces(...) could be useful? Or a switch to make cleanup_namespaces optionally propagate namespace declarations "upwards" in the tree, if possible (i.e. there's no remapping of the prefix).
The latter, I think, maybe as an explicit nsmap that declares the namespaces on the Element that was passed in, iff they are used in the tree.
Have fun: https://github.com/lxml/lxml/commit/4a1c2e9ff3c99247ec1da2707b29e3bb336d641d Stefan