【发布时间】:2013-07-12 19:11:48
【问题描述】:
如何用minidom检查xml节点是否有python中的子节点?
我正在编写一个递归函数来删除 xml 文件中的所有属性,我需要在再次调用相同的函数之前检查一个节点是否有子节点。
我尝试过的: 我尝试使用 node.childNodes.length,但运气不佳。还有其他建议吗?
谢谢
我的代码:
def removeAllAttributes(dom):
for node in dom.childNodes:
if node.attributes:
for key in node.attributes.keys():
node.removeAttribute(key)
if node.childNodes.length > 1:
node = removeAllAttributes(dom)
return dom
错误代码: RuntimeError: 超出最大递归深度
【问题讨论】: