Andrey Skvortsov schrieb am 08.08.2018 um 17:49:
copy/deepcopy copies all xml content, but information about added methods is lost.
Here is small example: [------------ subclass.py-----------------] from __future__ import print_function from lxml import etree import copy
class DefaultElementClass(etree.ElementBase): def getLocalTag(self): return etree.QName(self.tag).localname
def printInformation(x): print(x, x.__class__, "getLocalTag" in dir(x))
a = DefaultElementClass() printInformation(a)
# printInformation(copy.copy(a)) printInformation(copy.deepcopy(a)) [-----------------------------------------]
Output:
True False False Expected output:
True True True How create copy of the element and keep all methods from subclass?
You need to register the classes for the specific elements. https://lxml.de/element_classes.html Stefan