【发布时间】:2021-01-28 16:12:31
【问题描述】:
我有以下 xml:
</Page>
<Page ID="Page2" PHYSICAL_IMG_NR="2" HEIGHT="3300" WIDTH="2550">
<TopMargin HEIGHT="151" WIDTH="2550" VPOS="0" HPOS="0">
</TopMargin>
<LeftMargin HE<IGHT="2771" WIDTH="143" VPOS="151" HPOS="0">
</LeftMargin>
<RightMargin HEIGHT="2771" WIDTH="143" VPOS="151" HPOS="2407">
</RightMargin>
<BottomMargin HEIGHT="378" WIDTH="2550" VPOS="2922" HPOS="0">
<TextBlock>
</TextBlock>
</BottomMargin>
<PrintSpace>
</PrintSpace>
</Page>
我想将BottomMargin 标记及其内容移动到xml 的底部(在此示例中位于PrintSpace 标记之后)对于每个Page 标记。
我该怎么做?
我正在通过以下方式读取 xml:
使用 open(xml, "r") 作为文件:
content = file.readlines()
content = "".join(content)
soup = bs.BeautifulSoup(content, 'lxml')
【问题讨论】:
标签: python-3.x xml beautifulsoup xml-parsing