Reputation: 63
There is a string object with xml content. In python, I used etree to pretty print it. It works well in python 2.x, but fails to be shown in python 3.x.
from lxml import etree
print etree.tostring(etree.fromstring(patternXML), pretty_print=True)
I expect the xml is shown well as line breaks, but the actual output is bytes type and "\n" is shown instead of line break.
Upvotes: 1
Views: 130
Reputation: 63
It has been resolved by changing "tostring" to "tounicode" as below.
print etree.tounicode(etree.fromstring(patternXML), pretty_print=True)
Upvotes: 4