私は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 --> >
最初の4行は、私の意見ではあまり問題ではないはずですが、私は完全を期すためにそれらを含める:
私のファイルの先頭には、次のようになります。私の問題はTEI要素から始まります。 だから私のコードは、これは次のようになりますコピーするには:
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
は前にいくつかの時点で割り当てられ、私の質問のために重要ではありません。だから、私のコードは私にこの行を返す:
この唯一のものは、このxml:id
属性です。私はこの仕様ページを見つけました:https://www.w3.org/TR/xml-id/と私はそれがFAQのlxmlでサポートされると言われています。
Btw、root.attrib["xml:id"]
は実行可能な属性名ではありません。
私のIDをelemntのxml:id
属性に割り当てる方法を知っている人はいますか?