If you use cElementTree and try to create an XML file that uses some extra XML namespaces, you will encounter a wierd situation when the final file is written.
For example, I wanted to add the Creative Commons RSS module in a feed. What I expected to see in the XML file was the following:
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" . . <creativecommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativecommons:license>
What I got was the following:
ns0:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:ns0="http://backend.userland.com/creativeCommonsRssModule" . . <ns0:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</ns0:license>
This is totally correct, but how on earth could I get the namespace declaration and the CC element written as I wrote in the first example? After a lot of web searching I found a blog post that deals exactly with this problem.
Namespace Declarations With cElementTree by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2006 - Some Rights Reserved