【发布时间】:2021-05-07 17:02:26
【问题描述】:
我有一个 xml:
<?xml version="1.0" encoding="UTF-8"?>
- <note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
现在我想在note下添加一个id元素和它的值,输出应该是这样的:
<?xml version="1.0" encoding="UTF-8"?>
- <note>
<id>3</id>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
有朋友可以帮忙吗?
【问题讨论】:
-
你尝试了什么?你的代码在哪里?你检查是否有
insert()?你收到错误信息了吗?始终将有问题的完整错误消息(从“Traceback”一词开始)(不是评论)作为文本(不是屏幕截图,不是指向外部门户的链接)。还有其他有用的信息。 -
在
<note>之前有-吗?它可能是不正确的 XML,lxml读取有问题。
标签: python python-3.x xml lxml