[英]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 ( < ; ) rather than their numeric values ( < ; ). 我正在使用lxml和python生成xml文档(仅使用etree.tostring(root)),但目前生成的xml与命名实体(&lt;)一样显示html实体,而不是其数值(&#60;)。 。 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("<","<")
" for those characters. 如果需要此功能,则可能必须对字符串进行另一遍传递,并对这些字符手动执行“
outputString.replace("<","<")
“。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.