Reputation: 7739
I have an lxml Element
object:
>>> from lxml import etree
>>> xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<state type=\"before_battle\">\n</state>"
>>> etree.fromstring(xml_str.encode('utf-8'))
<Element state at 0x7fd04b957e48>
How to get the string dump of Element
?
Upvotes: 14
Views: 15439
Reputation: 222862
first store the element object in a variable
>>> d = etree.fromstring(xml_str.encode('utf-8'))
Then use the tostring
function from the lxml.etree
module:
>>> etree.tostring(d)
'<state type="before_battle">\n</state>'
For additional use cases, you can check out the lxml.etree
Tutorial.
Upvotes: 19