[lxml-dev] Converting an objectified lxml tree to a standard etree one.
John Krukoff
jkrukoff at ltgc.com
Mon Jun 22 20:57:50 CEST 2009
On Sat, 2009-06-20 at 07:51 +0200, Stefan Behnel wrote:
> Hi,
>
> John Krukoff wrote:
> > 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?
>
> I would say so. The problem is that if I allow changing the element lookup
> while the tree is alive in Python space (which would be required since you
> need to pass at least one Element instance into lxml to request the
> change), lxml would have to replace the proxies used inside the tree, which
> would mean that all live proxies in the tree would become Zombies
> (including the one you passed). That's rather dangerous.
>
> Deep copying the tree and returning a root node from the new parser context
> would be a solution if you need the tree in memory, which I assume is the
> case here. But IIRC, there isn't currently a way to deep-copy the tree so
> that it uses a new element lookup.
>
Yeah, this sounds like what I'll hope for in the future to make this
more efficient. I won't hold my breath though, and it looks like the
worst performance hit I'm seeing in my test cases is the assert which
checks the tree to make sure I'm not leaking any objectify elements
unintentionally. Obviously not a real problem. :)
[ snipped for length ]
> Hmm, yes, that looks weird. It works with lxml.etree, but not with
> lxml.objectify. Could you please file a bug report on this?
>
> Stefan
Bug report filed. Side note, having to register for bug reports is
always a pain. I don't think I've ever actually reused one of those
logins.
--
John Krukoff <jkrukoff at ltgc.com>
Land Title Guarantee Company
More information about the lxml-dev
mailing list