如何在Python中使用命名空间生成XML文档?
当前,您无法直接将命名空间添加到XML文档,因为内置的Pythonxml包尚不支持命名空间。因此,您需要将命名空间添加为标记的常规属性。例如,
import xml.dom.minidom
doc = xml.dom.minidom.Document()
element = doc.createElementNS('http://hello.world/ns', 'ex:el')
element.setAttribute("xmlns:ex", "http://hello.world/ns")
doc.appendChild(element)
print(doc.toprettyxml())这会给你文件,
<?xml version="1.0" ?> <ex:el xmlns:ex="http://example.net/ns"/>
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短