tags:

views:

118

answers:

1

Heyas

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 ; ). How exactly do I go about changing this so that the result uses the numeric values instead of the names?

Thanks

+1  A: 

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

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.

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.

Brian