Hi everyone.
I am trying to print a XML file using lxml and Python.
Here is the code:
>>> from lxml import etree
>>> root = etree.Element('root')
>>> child = etree.SubElement(root, 'child')
>>> print etree.tostring(root, pretty_print = True, xml_declaration = True, encoding = None)
Output:
<?xml version='1.0' encoding='ASCII'?>
<root>
<child/>
</root>
As you can see, I have declared encoding = None
, however it still shows encoding = 'ASCII'
in the final output. Which I guess is expected. If I don't put in the encoding
tag, it still shows ASCII.
Is there any way I can just get the XML version tag and not the encoding part? I want the output to be like this:
<?xml version='1.0'>