创建!ENTITY定义 [英] creation of !ENTITY definition
本文介绍了创建!ENTITY定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用python lxml如何创建!ENTITY定义,请注意,我想创建而不是解析.
With python lxml how can I create a !ENTITY definition, Note I want to create rather than parse.
那是我想创建一些包含另一个文件的 xml,因此需要一个 !ENTITY 定义
That is I want to create some xml that has an include of another file, hence the need for an !ENTITY definition
推荐答案
您应该能够将doctype声明(带有具有ENTITY声明的内部子集)创建为字符串,并在序列化时传递它(使用tostring()或write()).
You should be able to create the doctype declaration, with the internal subset that has the ENTITY declaration, as a string and pass that when you serialize (with tostring() or write()).
示例...
from lxml import etree
doctype = """<!DOCTYPE doc [
<!ENTITY ent SYSTEM "another_doc.xml">
]>"""
doc = etree.Element("doc")
ent = etree.Entity("ent")
doc.append(ent)
print(etree.tostring(doc, doctype=doctype).decode())
打印...
<!DOCTYPE doc [
<!ENTITY ent SYSTEM "another_doc.xml">
]>
<doc>&ent;</doc>
这篇关于创建!ENTITY定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文