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

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


Hi!

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'
      xmlns:isbn='urn:ISBN:0-395-36341-6'>
    <title>Cheaper by the Dozen</title>
    <isbn:number>1568491379</isbn:number>
</book>

### 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</
ns1:number>
</ns0:book>

### 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</
ns1:number>
</book>

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
ElementTree?


Regards Peter



More information about the XML-SIG mailing list