问题描述
我有自己的类来表示 Node
树的 XML
。我正在寻找一种方法来生成 scheme
- 具有所有标签和属性的最小树。
我所说的方案是指一棵树,其中所有标签只出现一次,并且每个标签都有所有可能的属性和子项。
因此,如果 root
有多个 product
子级,其中第一个 product
具有属性 name="some name"
而没有子级,而最后一个 product
具有属性 class="someclass"
和一个孩子 image
,方案树将有一个 root
,一个孩子 product
具有两个属性 name
和 class
和一个孩子 {{1} }.
image
我已经创建了一个 class SchemeNode():
def __init__(self,tag=None,text=None,parent=None,many=False,attrs=None):
self.tag = tag
self.text = text
self.parent: Node = parent
self.children = set()
self.many = many
self.attrs = attrs if attrs else {} # name,class etc...
@property
def siblings(self):
return self.parent.children
def add_child(self,child):
child.parent = self
self.children.add(child)
def __str__(self):
return f'Node [{self.tag}]'
,最终会创建这样的方案,但它引发了 SchemeNodeService
,我认为有一种更优雅的方法来做到这一点。
也许 BFS 会更好?
max recursion exceeded
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)