我尝试创建一个这样的 XML 文件:
<pico:record xsi:schemaLocation="http://purl.org/pico/1.0/ http://www.culturaitalia.it/pico/schemas/1.0/pico.xsd>
<dc:identifier>work_3117</dc:identifier>
</pico:record>
我使用这段代码:
from lxml import etree
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation="http://purl.org/pico/1.0/ http://www.culturaitalia.it/pico/schemas/1.0/pico.xsd"
ns = "{xsi}"
root=etree.Element("pico:record", attrib={"{" + xsi + "}schemaLocation" : schemaLocation})
etree.SubElement(root, "dc:identifier").text = "work_3117"
print(etree.tostring(root, pretty_print=True))
结果不起作用,python告诉我:
ValueError: 无效的标签名称 u'pico:record'
如果我将 'pico:recors' 更改为 'record' 错误是:
ValueError: 无效的标签名称 u'dc:identifier'