View Single Post
Old 05-23-2011, 09:47 PM   #4
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: 26,436
Karma: 5383257
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Code:
for navpoint in root.xpath('//{namespace}navPoint'):
   if test_navpoint_for_removal(navpoint):
      p = navpoint.getparent()
      p.remove(navpoint)
      for child in reversed(navpoint):
         p.insert(idx, child)
You'll have to do a bit of monkeying with the text/tail of various elements to preserve indentation, but that's about it.
kovidgoyal is offline   Reply With Quote