[XML-SIG] add Namespace Defaulting to ElementTree.write()

Peter Hoffmann tosh54 at gmail.com
Mon Jul 16 04:39:15 CEST 2007


As I somtimes have to look  at or even edit xml markup generated by
ElementTree, it would be a lot easier if ElementTree could use
Namespace Defaultig  as described in http://www.w3.org/TR/REC-xml-names/#defaulting

Here is an example what I mean:
### raw input
<book xmlns='urn:loc.gov:books'
    <title>Cheaper by the Dozen</title>

### normal ElementTree output
<ns0:book xmlns:ns0="urn:loc.gov:books">
    <ns0:title>Cheaper by the Dozen</ns0:title>
    <ns1:number xmlns:ns1="urn:ISBN:0-395-36341-6">1568491379</

### with Patch/set default_namespace="urn:loc.gov:books"
<book xmlns="urn:loc.gov:books">
    <title>Cheaper by the Dozen</title>
    <ns1:number xmlns:ns1="urn:ISBN:0-395-36341-6">1568491379</

I wrote a small patch against ElementTree.py (Python 2.5.1
(r251:54863, May  2 2007, 16:56:35) so that one can set a namespace to
be used as a default namespace when serealising an xml tree. You can
find it at http://user.cs.tu-berlin.de/~tosh/elementtree/  Some basic
tests are provided in selftest.py and some examples in test.py.

Any chances that the patch or a funcionality like this gets added to

Regards Peter

More information about the XML-SIG mailing list