How can I print the object numbers in my XML document instead of entity names using python lxml?

I use lxml and python to create XML documents (just using etree.tostring (root)), but at the moment the resulting xml displays html objects as with named objects (& lt;), not their numeric values ​​(& # 60 ;). How exactly do I want to change this so that the result uses numeric values ​​instead of names?

thanks

+4
source share
1 answer

In the end, it looks like python code will call xmlNodeDumpOutput in the libxml2 library.

Unfortunately, there doesn't seem to be any way to tweak this to control the representation of such objects. By looking at .c objects in xmlEncodeEntitiesReentrant,> and and characters are hard-coded to always use the corresponding XML object, so there is no way to force it to use numeric values.

If you need it, you probably have to do another pass on the line and manually execute " outputString.replace("<","<") " for these characters.

+2
source

All Articles