[issue18304] ElementTree -- provide a way to ignore namespace in tags and seaches

jonathan miller report at bugs.python.org
Wed Jul 27 09:00:50 EDT 2016


jonathan miller added the comment:

A flexible and pretty simple way opf loosening up handling namespaces would be to OPTIONALLY change what is done at parse time:

1.  Don't handle xmlns declarations specially.  Leave them as normal attributes, and the Element.attrib would have a normal entry for each.

2. Leave the abbreviation colon-separated prefix in front of the element
tags as they come in.

If the using code wants, it can walk the ElementTree contents making dictionaries of the active namespace declarations, tucking a dict reference into each Element.  Maybe put in an ElementTree method that does this, why not?

I'm interested in this topic because I wish to handle xml from a variety of different tools, some of which had their XML elements defined without namespaces.  They can use element names which are really common - like 'project' - and have no namespace definitions.  Worse:   if you put one in, the tool that originally used the element breaks.

Doing things as suggested gives the user the opportunity to look for matches using the colonized names, to shift namespace abbrevs easily, and to write out nicely namespaced code with abbrevs on the elements easily.

This would be OPTIONAL:  the way etree does it now, full prefixing of URI, is the safe way and should be retained as the default.

----------
nosy: +jjmiller50

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18304>
_______________________________________


More information about the Python-bugs-list mailing list