【发布时间】:2021-12-27 14:30:31
【问题描述】:
我有脚本应该从 XML 文件中过滤掉一些元素。我这样做是因为我确切地知道什么是元素深度,有多少孩子...... 但是你能不能给我一个例子,说明如何在不知道嵌套深度的情况下做到这一点?
代码如下:
def Filter_Modules(folder_name, corresponding_list):
for element in delta_root.iter('folder'):
if element.attrib.get('name') == str(folder_name):
corresponding_list.append(element)
for child in element:
corresponding_list.append(child)
for ch in child:
corresponding_list.append(ch)
for c in ch:
corresponding_list.append(c)
欢迎所有建议..
【问题讨论】:
-
分享xml(确保它是有效的!)并解释你需要什么。
标签: python xml list nested children