【发布时间】:2021-09-12 18:28:00
【问题描述】:
我有一个示例 XML 文件:
<Root>
<Parent_1>
<Child_1> Text 1 </Child_1>
<Child_2> Text 2 </Child_2>
</Parent_1>
<Parent_2>
<Child_3> Text 3 </Child_3>
<Child_4> Text 4 </Child_4>
</Parent_2>
我想将父标签附加到层次结构中。
<Root>
<Root_Parent_1>
<Root_Parent_1_Child_1> Text 1 </Root_Parent_1_Child_1>
<Root_Parent_1_Child_2> Text 2 </Root_Parent_1_Child_2>
</Root_Parent_1>
<Root_Parent_2>
<Root_Parent_2_Child_3> Text 3 </Root_Parent_2_Child_3>
<Root_Parent_2_Child_4> Text 4 </Root_Parent_2_Child_4>
</Root_Parent_2>
</Root>
有人可以帮我尝试阅读文件并附加标签吗?
【问题讨论】:
-
到目前为止你尝试过什么?请向我们展示您的代码:minimal reproducible example
标签: python python-3.x xml append parent-child