I have this xml from sql, and I want to do the same by python 2.7 and lxml
<?xml version="1.0" encoding="utf-16"?> <results> <Country name="Germany" Code="DE" Storage="Basic" Status="Fresh" Type="Photo" /> </results> Now I have:
from lxml import etree # create XML results= etree.Element('results') country= etree.Element('country') country.text = 'Germany' root.append(country) filename = "xmltestthing.xml" FILE = open(filename,"w") FILE.writelines(etree.tostring(root, pretty_print=True)) FILE.close() Do you know how to add rest of attributes?
<country>Germany</text>, not as an attribute, which is what you want/claim.