下面是我用来获取给定节点的所有子节点列表的代码片段。但是 nextSibling() 永远不会返回 null 所以 while 循环永远执行。请帮忙。
children = [ ]
children.append(documentElement.firstChild())
curr_node = children[0]
while curr_node.nextSibling():
print curr_node, len(children)
children.append(curr_node.nextSibling())
curr_node = curr_node.nextSibling()