如何在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 婆婆高寿祝福语大全简短