View Single Post
Old 03-11-2017, 10:54 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There's no direct way to modify namespaces in lxml. Instead you'd have to clone the tree, somethinf like

Code:
from calibre.ebooks.oeb.parse_utils import clone_element

nsmap = root.nsmap.copy()
nsmap['my namespace prefix'] = 'my namespace'
newroot = clone_element(root, nsmap, in_context=False)
container.replace(name, newroot)
kovidgoyal is online now   Reply With Quote