我已经follwing XML文件中插入一个XML节点的孩子在另一个XML节点:如何与Python
<root>
<nodeA>
<childrens_A>
</nodeA>
<nodeB>
<childrens_B>
</nodeB>
<nodeA>
<childrens_A>
</nodeA>
<nodeB>
<childrens_B>
</nodeB>
</root>
我想要得到的东西像节点A和B相等的
<root>
<nodeA>
<childrens_A>
<childrens_B>
</nodeA>
<nodeA>
<childrens_A>
<childrens_B>
</nodeA>
</root>
号码。 我只能从标准的python库导入。由于访问限制,我无法导入lxml
。所以我想限制from xml.etree import ElementTree as et
我的代码是:提前
from xml.etree import ElementTree as et
tree = et.parse(path_in)
root = tree.getroot()
for child in root.gethcildren()
if child.tag == "nodeA"
#insert children of nodeB in nodeA
tr.write(path_out)
谢谢!
在您期望的结果中,您是否指节点B下的节点A下的''标记和节点B下的''标记?现在你正在重新安排不同父母下的孩子。 –
Parfait
我在nodeB下的预期结果和。所以我想在NodeA中插入nodeB的子节点,然后删除空节点B –