[lxml-dev] Converting an objectified lxml tree to a standard etree one.

John Krukoff jkrukoff at ltgc.com
Fri Jun 19 22:18:26 CEST 2009


Is the best way to convert an objectified (with lxml.objectify) element
tree to a standard etree based one just to serialize and reparse? Is the
reverse transform just as hard?

As a use case, I've been experimenting with lxml.objectify, and quite
liking it. However, I've a large library of support functions that I
want to use that expect plain etree elements, and I'm trying to find an
efficient way to convert between the two. I care more about memory than
CPU time.

Additionally, there's something odd about the objectify module that
prevents help from working:

>>> help( objectify )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site.py", line 430, in __call__
    return pydoc.help(*args, **kwds)
  File "/usr/lib/python2.6/pydoc.py", line 1720, in __call__
    self.help(request)
  File "/usr/lib/python2.6/pydoc.py", line 1766, in help
    else: doc(request, 'Help on %s:')
  File "/usr/lib/python2.6/pydoc.py", line 1508, in doc
    pager(render_doc(thing, title, forceload))
  File "/usr/lib/python2.6/pydoc.py", line 1503, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/usr/lib/python2.6/pydoc.py", line 327, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/usr/lib/python2.6/pydoc.py", line 1086, in docmodule
    inspect.getclasstree(classlist, 1), name)]
  File "/usr/lib/python2.6/inspect.py", line 720, in getclasstree
    for parent in c.__bases__:
TypeError: 'lxml.objectify._ObjectifyElementMakerCaller' object is not
iterable

-- 
John Krukoff <jkrukoff at ltgc.com>
Land Title Guarantee Company



More information about the lxml-dev mailing list