13 May
2018
13 May
'18
5:45 p.m.
Peng Yu writes:
I just realize that tostring() makes changes to symbols like =C2=B0. If I just to strip the outermost tag, without changing anything to the internal text. How to do it? Thanks.
from lxml import etree tree =3D etree.XML('<foo>25/15=C2=B0C <bar>abc</bar></foo>') print etree.tostring(tree)
The output of the above code is the following.
<foo>25/15°C <bar>abc</bar></foo>
Check the lxml documentation for a way to run tostring without XML/HTML entities. Alternatively, replace them afterwards; I don't think it's in Python 2, but the module html.entities may be helpful.