使用ElementTree在Python中可视化XML子级?

2024-05-26 16:29:39 发布

您现在位置:Python中文网/ 问答频道 /正文

给定XML:

<Anthology>
    <Price></Price>
    <Book>
        <Price></Price>
        <Leaflet>
            <Title>War</Title>
            <Price>20</Price>
        </Leaflet>
        <Leaflet>
            <Title>Peace</Title>
            <Price>30</Price>
        </Leaflet>
    </Book>
    <Book>
        <Price>60</Price>
    </Book>
</Anthology>

我想以分层方式更新“价格”标签并打印:

Anthology price: 110, Book 1 price: 50, Book 2 price: 60

或者在pseudo中,我想搜索一个索引项,并让它的'price'标签反映所有子级'price'标签的总和。在

有什么建议可以用ElementTree来攻击它?在


Tags: title分层方式价格标签xmlprice子级

热门问题