我想用python替换xml中的空节点

2024-05-19 13:25:22 发布

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

我想用python替换结束语<category/>Passenger cars </category>。我只需要在类别开始和结束xml标记之间添加“乘用车”

        categories=xml.getElementsByTagName('category')[0].toxml()
        if categories=='<category/>':
            categories=categories.replace('<category/>','<category>Passenger cars</category>')

Tags: 标记ifxml类别carsreplacecategoriescategory