«
»

Namespace Declarations With cElementTree

May 16th, 2006 by George Notaras

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.

The Namespace Declarations With cElementTree by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Terms and conditions beyond the scope of this license may be available at www.g-loaded.eu.

Related Articles

Tags: , ,

Bookmark and Share

Comments are automatically disabled after a certain period of time. Further discussion about the published content is still possible though in the G-Loaded Forums.