leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.
332 stars 31 forks source link

How can I set the version and encoding of a XML document? #34

Closed rn4n closed 7 years ago

rn4n commented 7 years ago

How can I set the xml version and encoding of the document? For example, I need to put this on the first line:

<?xml version="1.0" encoding="windows-1252" standalone="no"?>

My code:


doc, tag, text = Doc().tagtext()

# insert the first line here.

with tag('generated-tests'):
    for key, value in market.items():
         doc.stag('test', testname=key, testoutput=value)

return indent(doc.getvalue())
rn4n commented 7 years ago

Solved using doc.asis().


doc, tag, text = Doc().tagtext()

doc.asis('<?xml version="1.0" encoding="windows-1252" standalone="no"?>')

with tag('generated-tests'):
    for key, value in market.items():
         doc.stag('test', testname=key, testoutput=value)

return indent(doc.getvalue())