简体   繁体   English

如何使用python的lxml在xml文档中打印实体编号而不是实体名称?

[英]How can I print entity numbers in my xml document instead of entity names using python's lxml?

I'm using lxml and python to generate xml documents (just using etree.tostring(root) ) but at the moment the resulting xml displays html entities as with named entities ( &lt ; ) rather than their numeric values ( &#60 ; ). 我正在使用lxml和python生成xml文档(仅使用etree.tostring(root)),但目前生成的xml与命名实体(<)一样显示html实体,而不是其数值(<)。 。 How exactly do I go about changing this so that the result uses the numeric values instead of the names? 我该如何精确地更改它,以便结果使用数字值而不是名称?

Thanks 谢谢

Ultimately, it looks like the python code will call xmlNodeDumpOutput in the libxml2 library. 最终,看起来python代码将在libxml2库中调用xmlNodeDumpOutput

Unfortunately, it doesn't look like there is any way to configure this to control how such entities are represented. 不幸的是,似乎没有任何方法可以配置它来控制这些实体的表示方式。 Looking at entities.c in xmlEncodeEntitiesReentrant, the < > and & characters are hardcoded to always use the appropriate XML entity, so there seems no way to force it to use numeric values. 查看xmlEncodeEntitiesReentrant中的entities.c,<>和&字符被硬编码为始终使用适当的XML实体,因此似乎没有办法强迫它使用数字值。

If you need this, you'll probably have to perform another pass on the string, and manually perform " outputString.replace("&lt;","&#60;") " for those characters. 如果需要此功能,则可能必须对字符串进行另一遍传递,并对这些字符手动执行“ outputString.replace("&lt;","&#60;") “。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Python 中将 *all* 字符转义为其相应的 html 实体名称和数字? - How can I escape *all* characters into their corresponding html entity names and numbers in Python? 如何使用 python 中的 lxml 模块按子元素对 xml 文件进行排序? - How can I sort my xml file by a subelement, using lxml module in python? 当我打印列表而不是使用列表中的名称时,输出将显示索引号。 Python 2D清单 - When I print my list instead of using the names in the list the output shows the index numbers. Python 2D-Lists 如何在python中使用lxml读取带有实体引用的mathML - How to read mathML with entity references using lxml in python 我如何使用Python中的LXML捕获XML文件的所有元素名称? - How I do capture all of the element names of an XML file using LXML in Python? 如何使用 python lxml 删除 XML 文档根元素之外的注释 - How do I remove a comment outside of the root element of an XML document using python lxml 如何使用lxml在XML元素名称中使用“:”? - How do I use “:” in XML element names using lxml? 使用带有 Python 的 lxml 的 XML 目录? - Using an XML catalog with Python's lxml? 如何使用 bs4 或 lxml 在 Python 中找到 XML 标记的文本行? - How can I get the line of the text where an XML tag is found in Python using bs4 or lxml? 我如何从使用python的lxml etree和xpath选择的节点获取(打印)所有内部html? - How could I get (print) all inner html from node which I select using python's lxml etree and xpath?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM