Gergely K. schrieb am 02.08.21 um 12:14:
In my project I generate an xml file, which is autoformatted with an
external tool. However, the external tool uses a different quote for the
xml declaration. lxml with the code
tree.write(
os.path.join(project_dir, 'artifact.xml'),
pretty_print=True,
xml_declaration=True,
encoding='utf-8')
produces
<?xml version="1.0" encoding="UTF-8"?>
but the external tool autoformats it to:
<?xml version='1.0' encoding='UTF-8'?>
Is it possible to change the quoting of the generated xml declaration?
No, it's not configurable, and it follows what Python's ElementTree uses on
serialisation. Note that there is no semantic difference between the two
versions, they are both perfectly normal XML.
You can write your own declaration, though, and tell lxml not to do it
itself. Just pass `xml_declaration=False` to the serialiser.
Stefan
_______________________________________________
lxml - The Python XML Toolkit mailing list -- lxml@python.org
To unsubscribe send an email to lxml-le...@python.org
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: arch...@mail-archive.com