我想使用Python的xml.etree.ElementTree模块解析一个xml文档。但是,我希望生成的tree对象中的所有元素都有一些我定义的类方法。这建议创建我自己的Python的element类的子类,但是我在告诉解析器在解析时使用我自己的element子类而不是内置的类时遇到了麻烦。例如,假设我希望树中的节点有一个名为custommethod()的新方法。为此,我创建了一个元素子类:
class MyEle
import xml.etree.ElementTree as ET
fileXml ='C:\\Users\\Documents\\config.xmlroot.insert(1, comment) # 1 is the index where comment is inserted print("Done&