Search code examples
pythonxmllxmlelementtree

Convert xml.etree.ElementTree.Element to lxml.Element


I'm developing a package that can be used by both users of lxml and the default xml package. ATM I have a small try:except for the lxml import, but sometimes the user uses functions like dump() from the default xml.etree which don't support the lxml.Element.

How can I convert between lxml Element and default Element in an efficient way without passing through a string or doing custom recursive processing?


Solution

  • Per @Parfait, there is not easy way of doing it.

    Pandas for example implements the same interface twice for lxml and xml.etree, and rely on the fact that the APIs are mature and stable, so there is no need for continued maintenance.