1
我在用lxml重建一个TEI-XML文件。用lxml编写xml:id属性
我的文件的开头是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://www.ssrq-sds-fds.ch/tei/TEI_Schema_SSRQ.rng"
type="application/xml"
schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://www.ssrq-sds-fds.ch/tei/TEI_Schema_SSRQ.rng"
type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<?xml-stylesheet type="text/css"
href="https://www.ssrq-sds-fds.ch/tei/Textkritik_Version_tei-ssrq.css"?>
<TEI xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns="http://www.tei-c.org/ns/1.0" n=""
xml:id="[To be generated]" <!-- e.g. StAAG_U-17_0007a --> >
前四行不应该太大的关系在我看来,但我列入他们的完整性。我的问题始于TEI-Element。 所以我的代码复制,这看起来是这样的:
NSMAP = {"xml":"http://www.tei-c.org/ns/1.0",
"xi":"http://www.w3.org/2001/XInclude"}
root = et.Element('TEI', n="", nsmap=NSMAP)
root.attrib["id"] = xml_id
root.attrib["xmlns"] = "http://www.tei-c.org/ns/1.0"
弦乐xml_id
在之前的一些点被分配并不要紧,我的问题。所以我的代码返回我这一行:
<TEI xmlns:xi="http://www.w3.org/2001/XInclude"
n=""
id="StAAG_U-17_0006"
xmlns="http://www.tei-c.org/ns/1.0">
所以这是唯一缺少的就是这种xml:id
属性。我发现这个规范页面:https://www.w3.org/TR/xml-id/,我知道它在FAQ的lxml中被支持。
Btw,root.attrib["xml:id"]
不起作用,因为它不是一个可行的属性名称。
那么,有谁知道我可以如何将我的id分配给elemnt的xml:id
属性?